Transaction Control in SQL

From the SQL cheat sheet ยท Transactions ยท verified Jul 2026

Transaction Control

BEGIN, COMMIT, ROLLBACK, and savepoints.

sql
BEGIN TRANSACTION;

UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;

COMMIT;
-- or ROLLBACK; to undo
๐Ÿ’ก Transactions are atomic โ€” either all operations succeed (COMMIT) or none do (ROLLBACK)
โšก Use savepoints for partial rollbacks without losing the entire transaction
๐Ÿ“Œ Always COMMIT or ROLLBACK โ€” uncommitted transactions hold locks and block other queries
๐ŸŸข Most databases auto-commit individual statements โ€” BEGIN is needed for multi-statement atomicity
transactionscommitrollbacksavepoint
Back to the full SQL cheat sheet