Transactions and ACID

Transactions group multiple database operations into one reliable unit. This matters for payments, order creation, inventory, and any workflow where partial data is dangerous.

Transaction Flow

BEGIN;

UPDATE accounts
SET balance = balance - 500
WHERE id = 1;

UPDATE accounts
SET balance = balance + 500
WHERE id = 2;

COMMIT;

Rollback

Use ROLLBACK when any step fails. In testing, verify that failed workflows do not leave half-created records.

BEGIN;
INSERT INTO orders(customer_id, status) VALUES (101, 'CREATED');
-- payment failed
ROLLBACK;

ACID

PropertyMeaning
AtomicityAll steps succeed or none do.
ConsistencyRules and constraints remain valid.
IsolationParallel transactions do not corrupt each other.
DurabilityCommitted data survives failures.

QA Scenarios