Skip to content
C

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

sql
START 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

  • COMMIT can itself fail (e.g. a deferred constraint check that only runs at commit time in some databases) — code that assumes COMMIT always succeeds without checking for an error is a real class of application bug.
  • Under autocommit mode (22.12), every individual statement is implicitly followed by its own automatic commit — an explicit COMMIT is only meaningful once you've explicitly opened a multi-statement transaction with START TRANSACTION.
  • On the specific SQL judge platform used in this course, COMMIT only behaves correctly on a transactional storage engine (InnoDB) — on the default MyISAM engine, statements are effectively auto-committed regardless, so COMMIT/ROLLBACK have 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.

Mock Test

  • COMMIT - Quick Test

    8 questions on COMMIT.

    8 questions · 8 min · Medium
    Start Mock Test

Coding Problem