Commit a Fund Transfer
Easysql
Learn the Concept: COMMITWrite a transaction that transfers 200 from account id 1 to account id 2 and commits it. Debit account 1 by 200, credit account 2 by 200, then COMMIT.
sqlCREATE TABLE accounts ( id INTEGER PRIMARY KEY, balance INTEGER NOT NULL ) ENGINE=InnoDB;
Sample data:
sqlINSERT INTO accounts (id, balance) VALUES (1, 1000), (2, 500);
Example 1
Input
(none)
Output
id balance 1 800 2 700
Reference: START TRANSACTION; UPDATE accounts SET balance = balance - 200 WHERE id = 1; UPDATE accounts SET balance = balance + 200 WHERE id = 2; COMMIT; — ENGINE=InnoDB is required for this platform's transaction support to actually apply.
Related Problems
- Employees Without a ManagerEasy · sqlSolve Problem
- Engineering Team by SalaryEasy · sqlSolve Problem
- Duplicate EmailsEasy · sqlSolve Problem