Glossary

Transaction (DB)

A transaction is a unit of database work that either completes in full or not at all. If an error occurs during a money transfer between two accounts — after the debit but before the credit — the transaction rolls back and balances remain unchanged.

ACID properties

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.