TCL (Transaction Control Language) is the subset of SQL used to manage transactions — sequences of changes that should be applied as a unit, all-or-nothing. The keywords are:
- COMMIT — make the changes in the current transaction permanent.
- ROLLBACK — revert them, returning the database to the state it was in at the last commit (or the start of the transaction, if no commit has happened since).
- SAVEPOINT — create a checkpoint within a transaction that we can roll back to without abandoning the whole transaction.
A canonical example is transferring money between accounts:
START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;If either UPDATE fails — the network drops, the database crashes, a constraint is violated — the second statement might run while the first doesn’t, or vice versa, and one of the accounts ends up wrong. Wrapping the two statements in a transaction and committing them together guarantees that both changes happen or neither does. Should something go wrong mid-transaction, ROLLBACK undoes everything that hasn’t been committed.
Savepoints let us roll back partially within a complex transaction:
START TRANSACTION;
INSERT INTO orders ...;
SAVEPOINT after_order;
INSERT INTO order_items ...; -- might fail
ROLLBACK TO SAVEPOINT after_order; -- undoes order_items, keeps the order
COMMIT;Transactions are how databases guarantee ACID properties — Atomicity, Consistency, Isolation, Durability — that ordinary file-based storage can’t provide. The cost is performance: transactional operations are slower than their non-transactional equivalents, and the database has to maintain enough state (logs, lock tables) to roll back if needed.
The other three SQL sub-languages — DDL for structure, DML for data, DCL for permissions — handle different concerns. TCL is specifically about transactional control.