ACID properties
- Atomicity — all operations succeed or all are rolled back
- Consistency — the database moves from one valid state to another
- Isolation — concurrent transactions cannot see each other's uncommitted changes
- Durability — after COMMIT, changes are persisted even on failure
SQL syntax
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
If an error occurs between BEGIN and COMMIT — issue a ROLLBACK to undo all changes. Most drivers and ORMs wrap this automatically.