Transactions
A transaction is a unit of work that either completes fully (COMMIT) or is rolled back entirely (ROLLBACK). Transactions ensure ACID guarantees.
A transaction is a unit of work that either completes fully (COMMIT) or is rolled back entirely (ROLLBACK). Transactions ensure ACID guarantees.
START TRANSACTION;
UPDATE accounts SET balance = balance - 500 WHERE id = 1;
UPDATE accounts SET balance = balance + 500 WHERE id = 2;
-- If both updates succeed:
COMMIT;
-- If anything goes wrong:
-- ROLLBACK;
All statements between START TRANSACTION and COMMIT behave as a single atomic operation.