intermediateTransactions — ACID, COMMIT, ROLLBACK, SAVEPOINT

A bank transfer application deducts money from Account A but the credit to Account B fails. How do transactions prevent data corruption?

Without transaction: debit succeeds, credit fails → money disappears (inconsistency). With transaction: BEGIN; UPDATE accounts SET balance = balance - 1000 WHERE id = 1; UPDATE accounts SET balance = balance + 1000 WHERE id = 2; COMMIT. If the second UPDATE fails (e.g., account 2 doesn't exist, CHECK constraint violation, network error): the exception triggers ROLLBACK. The first UPDATE is also un

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What are the three main read anomalies in database transactions?← Back to all SQL questions