C · Write · advanced · Week 3 · Chapter 9 of 12
Transactions & isolation
BEGIN / COMMIT / ROLLBACK. ACID guarantees. Transfer money mental model: debit and credit must both succeed or both fail.
Path progress69%
Step 1 of 3
Transaction basics
BEGIN; multiple statements; COMMIT if all good, ROLLBACK on error. SQLite: BEGIN IMMEDIATE for writes.
Example
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
-- inspect; then COMMIT or ROLLBACK
COMMIT;Do this now
Transfer script: decrement account A, increment B — wrap in transaction.
Was this step clear?
Chapter learning outcomes
- BEGIN/COMMIT/ROLLBACK
- ACID intuition
- Isolation levels lite
- Deadlocks awareness
Clear these before you leave
Side quest
Failed insert rollback
Insert valid row + invalid row in txn; ROLLBACK; verify neither persisted.