What is a Transaction?
A transaction is a unit of work that is either fully completed or fully rolled back.
ACID Properties:
- Atomicity: All operations succeed or none
- Consistency: Database remains valid before and after
- Isolation: Transactions don't interfere
- Durability: Once committed, it stays
Example:
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;