Extras · Lesson 7 of 22

Transactions & ACID

Transactions group operations that must succeed or fail together.

Transfer money between accounts:

BEGIN TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;

ACID properties:

  • Atomicity - all or nothing
  • Consistency - rules always enforced
  • Isolation - transactions don't interfere
  • Durability - committed = permanent

If anything fails, ROLLBACK undoes everything.

Critical for: banking, e-commerce, any financial data.

Check your understanding

What does 'Atomicity' mean in ACID?