Overview

SQL Server defaults to lock-based READ COMMITTED: readers take shared locks and are blocked by writers. Two database options switch to row versioning (MVCC-like) instead, so readers neither block nor are blocked by writers: READ_COMMITTED_SNAPSHOT (RCSI) and ALLOW_SNAPSHOT_ISOLATION.

Core concepts

SettingBehaviour
READ COMMITTED (default, locking)Shared locks while reading; blocks behind writers
READ COMMITTED with READ_COMMITTED_SNAPSHOT ONEach statement reads the last committed version as of statement start; no S locks. Transparent to applications
SNAPSHOT (ALLOW_SNAPSHOT_ISOLATION ON, then SET TRANSACTION ISOLATION LEVEL SNAPSHOT)The whole transaction sees a consistent version; update conflicts raise error 3960
REPEATABLE READ, SERIALIZABLELocks held to end of transaction; range locks for serializable

Row versions are kept in a version store: in tempdb, or in the database itself when Accelerated Database Recovery (ADR) is enabled (2019+). Each versioned row carries a 14-byte pointer, so the first change to a row after enabling it widens it. Writers still block writers (they need the row lock).

Azure SQL Database enables RCSI by default; on-premises databases do not, including new ones.

Worked example

Session A: BEGIN TRAN; UPDATE dbo.Acct SET bal = bal - 10 WHERE id = 1; and wait. Session B: SELECT bal FROM dbo.Acct WHERE id = 1;. Measured on SQL Server 2022:

Database optionReader B
READ_COMMITTED_SNAPSHOT OFFreturned 100 after 8 s, when A rolled back (waited on LCK_M_S)
READ_COMMITTED_SNAPSHOT ONreturned 100 immediately (the last committed value)

Enabling it needs exclusive access to the database for a moment:

ALTER DATABASE kb SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;  -- disconnects other sessions
SELECT name, is_read_committed_snapshot_on, snapshot_isolation_state_desc FROM sys.databases;

Pitfalls and production notes

  • Version store growth: a long-open transaction prevents cleanup. Monitor sys.dm_tran_version_store_space_usage and tempdb space (sqlserver-storage-tempdb).
  • Code that relied on blocking (for example “read a row, then update based on it” assuming nobody else changed it) can now lose updates; use UPDLOCK hints or snapshot-mode conflict detection.
  • RCSI statement-level consistency still allows non-repeatable reads across statements (isolation-levels).
  • Test workloads before enabling: tempdb I/O and CPU rise because of version generation.
  • Prefer RCSI over NOLOCK; NOLOCK returns uncommitted data and can skip or duplicate rows.
  • PostgreSQL and Oracle behave this way by default (pg-mvcc).

Practice questions

  1. Which anomalies does RCSI still allow?
  2. What happens to a snapshot transaction that updates a row changed by another transaction since its start?
  3. Where do the row versions live with and without ADR?

References

  • Microsoft Learn, Snapshot isolation in SQL Server; Accelerated database recovery

isolation-levels · sqlserver-locking-blocking-deadlocks · sqlserver-storage-tempdb · pg-mvcc