Transactions and ACID Properties

A transaction is a logical unit of work, a sequence of operations that must be executed completely or not at all.

PropertyMeaningEnsured by
AtomicityAll or nothingRecovery manager (undo logs)
ConsistencyDatabase moves from one valid state to anotherConstraints + programmer
IsolationConcurrent transactions don't interfereConcurrency control
DurabilityCommitted changes survive crashesRecovery manager (redo logs)
SQL
START TRANSACTION;
UPDATE account SET balance = balance - 1000 WHERE acc_no = 101;
UPDATE account SET balance = balance + 1000 WHERE acc_no = 202;
COMMIT;   -- or ROLLBACK; to undo both

Transaction States

Text
Active → Partially Committed → Committed → Terminated
   │               │
   └──→ Failed ←───┘ → Aborted (rolled back) → Terminated

Concurrency Problems

  • Lost update (W-W conflict)
  • Dirty read: reading uncommitted data (W-R)
  • Unrepeatable read (R-W)
  • Phantom read: new rows appear in a repeated query
Track your progress through the DBMS course