COMMIT
COMMIT
Definition
COMMIT is the statement that ends a transaction SUCCESSFULLY, making all of its changes permanent (Durability, 22.8) and visible to other transactions.
How It Works
sqlSTART TRANSACTION; UPDATE accounts SET balance = balance - 200 WHERE id = 1; UPDATE accounts SET balance = balance + 200 WHERE id = 2; COMMIT;
Before COMMIT runs, both updates exist only within this transaction's own view (Isolation, 22.7) — other transactions still see the old balances. The instant COMMIT succeeds, the changes become permanent and visible to everyone. There is no way to undo a transaction after COMMIT has completed — any correction from that point on requires a NEW transaction with compensating statements.
Edge Cases and Pitfalls
COMMITcan itself fail (e.g. a deferred constraint check that only runs at commit time in some databases) — code that assumesCOMMITalways succeeds without checking for an error is a real class of application bug.- Under
autocommitmode (22.12), every individual statement is implicitly followed by its own automatic commit — an explicitCOMMITis only meaningful once you've explicitly opened a multi-statement transaction withSTART TRANSACTION. - On the specific SQL judge platform used in this course,
COMMITonly behaves correctly on a transactional storage engine (InnoDB) — on the defaultMyISAMengine, statements are effectively auto-committed regardless, soCOMMIT/ROLLBACKhave no observable difference.
Key Takeaways
- COMMIT ends a transaction successfully, making its changes permanent and visible to all other transactions.
- Once committed, a transaction cannot be undone — only a new, compensating transaction can adjust the data further.
- COMMIT is meaningless without an explicit transaction boundary if autocommit mode already committed each statement individually.