Rollback a Failed Transfer
Easysql
Learn the Concept: ROLLBACKWrite a transaction that attempts to transfer 300 from account id 1 to account id 2, but then rolls it back instead of committing. Debit account 1 by 300, credit account 2 by 300, then ROLLBACK.
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 1000 2 500
Reference: START TRANSACTION; UPDATE accounts SET balance = balance - 300 WHERE id = 1; UPDATE accounts SET balance = balance + 300 WHERE id = 2; ROLLBACK; — the balances must equal the original seed values exactly, proving the transaction left no trace.
Related Problems
- Employees Without a ManagerEasy · sqlSolve Problem
- Engineering Team by SalaryEasy · sqlSolve Problem
- Duplicate EmailsEasy · sqlSolve Problem