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