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
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
A bank transfer application deducts money from Account A but the credit to Account B fails. How do transactions prevent data corruption?