SQL & Relational Databases (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What are the 4 ANSI SQL Transaction Isolation Levels and their read phenomena?
senior LevelCode ExampleSystem DesignDatabases & SQL
In Simple Words: Isolation levels define how transactions interact concurrently:
- Dirty Read: Reading uncommitted changes made by another concurrent transaction (which might subsequently roll back!).
- Non-Repeatable Read: Re-reading a row within the same transaction returns different column values because another transaction modified and committed it.
- Phantom Read: Re-running a range query (
WHERE age > 25) returns newly inserted rows committed by another transaction.
text
Isolation Matrix:
┌──────────────────┬────────────┬─────────────────────┬──────────────┐
│ Isolation Level │ Dirty Read │ Non-Repeatable Read │ Phantom Read │
├──────────────────┼────────────┼─────────────────────┼──────────────┤
│ READ UNCOMMITTED │ YES │ YES │ YES │
│ READ COMMITTED │ NO │ YES │ YES │
│ REPEATABLE READ │ NO │ NO │ YES (Standard)│
│ SERIALIZABLE │ NO │ NO │ NO │
└──────────────────┴────────────┴─────────────────────┴──────────────┘