A transaction groups statements into one all-or-nothing unit. ACID Property Guarantee Atomicity All statements succeed or none do (ROLLBACK) Consistency Constraints hold before and after Isolation Concurrent transactions do not see each other's partial work Durability Committed data survives crashes Isolation levels and anomalies Level Dirty read Non-repeatable read Phantom read Read Uncommitted possible possible possible Read Committed (default in PostgreSQL, SQL Server) ✅ prevented possible possible Repeatable Read (default in MySQL InnoDB) ✅ ✅ possible Serializable ✅ ✅ ✅ \ InnoDB and PostgreSQL prevent most phantoms at Repeatable Read using MVCC. Practical rules Keep transactions short; never wait for user input inside one. Lock rows you intend to update: SELECT … FOR UPDATE…
Key Takeaways
Transactions are all-or-nothing: COMMIT or ROLLBACK.
Higher isolation prevents more anomalies but reduces concurrency.
Keep transactions short and lock rows with SELECT … FOR UPDATE.