SQL & Relational Databases (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Transaction Isolation Levels and Concurrency Anomalies.
senior LevelDatabases & SQL
In Simple Words: SQL-92 defines four transaction isolation levels to balance consistency against concurrency:
- Read Uncommitted: Suffers from Dirty Reads (reading uncommitted changes from another transaction that might roll back).
- Read Committed (Default in PostgreSQL): Prevents dirty reads; suffers from Non-Repeatable Reads (rereading the same row yields different data because another transaction committed an update).
- Repeatable Read (Default in MySQL InnoDB): Guarantees reading the same row snapshot; can suffer from Phantom Reads (new rows inserted by another transaction).
- Serializable: Highest isolation; eliminates all anomalies by executing transactions as if run sequentially.