Transaction Isolation Levels and Row Versioning
This lesson explains concurrency phenomena, the five isolation levels and how RCSI and snapshot isolation use row versions.
Learning outcomes
After completing this lesson, you will be able to:
- Describe dirty reads, non-repeatable reads, phantoms and lost updates.
- Distinguish between the isolation levels.
- Explain the difference between RCSI and SNAPSHOT isolation.
Concurrency phenomena
Isolation levels are defined by which anomalies they allow. A dirty read reads data that another transaction has not committed and may roll back. A non-repeatable read reads the same row twice in a transaction and gets different values because another transaction committed a change in between. A phantom occurs when a repeated range query returns new rows inserted by another transaction. A lost update occurs when two transactions read the same value and both write, so one overwrites the other.
Concurrency anomalies
The isolation levels
SQL Server and Azure SQL support five isolation levels, set with SET TRANSACTION ISOLATION LEVEL, which the following table compares.
| Level | Dirty reads | Non-repeatable reads | Phantoms | How it works |
|---|---|---|---|---|
| READ UNCOMMITTED | Possible | Possible | Possible | No shared locks (like NOLOCK) |
| READ COMMITTED | No | Possible | Possible | Short shared locks, or row versions when RCSI is on |
| REPEATABLE READ | No | No | Possible | Shared locks held until the transaction ends |
| SERIALIZABLE | No | No | No | Key-range locks held until the transaction ends |
| SNAPSHOT | No | No | No | Reads a consistent snapshot from row versions as of the transaction start |
Higher pessimistic levels hold more locks for longer, which increases blocking and deadlocks. READ UNCOMMITTED avoids blocking but can return uncommitted, duplicated or missing rows, so it is not suitable for data that must be correct.
Choosing an isolation level
Row versioning: RCSI and SNAPSHOT
With read committed snapshot isolation (RCSI) on, READ COMMITTED transactions read the last committed version of each row as of the start of each statement, from the version store, instead of taking shared locks, so readers and writers do not block each other. SNAPSHOT isolation reads as of the start of the transaction, giving a consistent view across several statements; if a snapshot transaction then updates a row that another transaction changed after the snapshot started, it fails with update conflict error 3960 and must be retried. In Azure SQL Database both are enabled by default; in SQL Server they are enabled with ALTER DATABASE ... SET READ_COMMITTED_SNAPSHOT ON and ALLOW_SNAPSHOT_ISOLATION ON. Row versioning costs version store space and some extra I/O.
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
BEGIN TRANSACTION;
SELECT SUM(OnHand) FROM Inventory.Stock WHERE WarehouseID = 3; -- consistent snapshot
SELECT COUNT(*) FROM Inventory.Stock WHERE WarehouseID = 3; -- same snapshot
COMMIT;The following diagram compares what two statements see under each level.

Row versioning
A consistent multi-statement report
A month-end report runs five SELECT statements in one transaction and must see the data exactly as it was when the report started, while order entry continues without being blocked. The database is in Azure SQL Database. Which isolation level should the report use?
Use SNAPSHOT isolation. It reads every statement from the same point-in-time version without taking shared locks, so it neither blocks nor is blocked by order entry. READ COMMITTED with RCSI is consistent only per statement, so totals in different statements could disagree, and SERIALIZABLE would block order entry for the duration of the report.
Does RCSI give a consistent view across several statements in one transaction?
Show answer
No. RCSI is consistent per statement; SNAPSHOT isolation is consistent for the whole transaction.
Exam Tips
Remember for the exam
- Readers and writers do not block each other: RCSI (per statement) or SNAPSHOT (per transaction).
- SNAPSHOT update conflicts raise error 3960; retry the transaction.
- No phantoms with locking: SERIALIZABLE.
- READ UNCOMMITTED and NOLOCK can return incorrect results.