skip to content

In SQL Server, how do the READ_COMMITTED_SNAPSHOT and ALLOW_SNAPSHOT_ISOLATION database options differ in what readers see and how writers fail?

level: middleimportance: must knowfreq 72%

answer

  1. two database options, two scopes
  2. statement start versus transaction start
  3. one needs SET TRANSACTION ISOLATION LEVEL
  4. which side can raise Msg 3960

basics

~20 s

READ_COMMITTED_SNAPSHOT makes the default READ COMMITTED level read row versions as of each statement's start, transparently. ALLOW_SNAPSHOT_ISOLATION only permits SET TRANSACTION ISOLATION LEVEL SNAPSHOT, which reads as of transaction start and aborts with Msg 3960 on an update conflict.

solid answer

~40 s

Both options turn on row versioning for every modification in the database, but they expose it differently. `READ_COMMITTED_SNAPSHOT ON` changes what the default `READ COMMITTED` level means: each statement reads the last committed version as of the moment it started, readers take no row or page locks, and no application code changes. Writers still lock the rows they change, so an `UPDATE` that meets a competing writer waits instead of failing. `ALLOW_SNAPSHOT_ISOLATION ON` changes nothing by itself; it only lets a session run `SET TRANSACTION ISOLATION LEVEL SNAPSHOT` before its transaction begins. That transaction then sees one consistent view for its whole life, and if it modifies a row that another transaction changed and committed after the snapshot transaction started, SQL Server aborts it with Msg 3960, an update conflict the application must retry.

code

sql · 8 lines
sql
ALTER DATABASE Sales SET ALLOW_SNAPSHOT_ISOLATION ON;
ALTER DATABASE Sales SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;

SELECT name,
       is_read_committed_snapshot_on,
       snapshot_isolation_state_desc
FROM sys.databases
WHERE name = N'Sales';

go deeper

for a junior

Remember that SQL Server's default READ COMMITTED is lock-based unless READ_COMMITTED_SNAPSHOT is on, and that SNAPSHOT is a separate level a session has to ask for.

for a middle

Explain the point in time each one reads from, statement versus transaction, and why only SNAPSHOT raises Msg 3960 when a write meets a row committed after it began.

for a senior

Show the operational side: the RCSI switch needs the database to itself, SNAPSHOT passes through PENDING_ON, and SNAPSHOT code needs a retry loop around the whole transaction.

for a principal

Frame which one to standardise: RCSI as a database-wide default that changes every reader at once, SNAPSHOT as a per-transaction opt-in whose conflicts application teams must own.

## Two switches on the same machinery SQL Server's default `READ COMMITTED` isolation level is **lock-based** on a fresh user database: a reader takes a shared (`S`) lock on each row or page as it reads and releases it once the row is read, so a reader waits behind any writer that holds an exclusive (`X`) lock. Two database options replace those shared locks with **row versioning**. When a row is modified, the previously committed image is copied to a **version store** and the current row carries a pointer to it, so a reader can follow the chain back to the version it is entitled to see. - `READ_COMMITTED_SNAPSHOT` (usually called **RCSI**) changes the meaning of the existing `READ COMMITTED` level. - `ALLOW_SNAPSHOT_ISOLATION` makes a separate `SNAPSHOT` isolation level available to sessions that ask for it. Both are `OFF` by default for user databases on SQL Server. Turning on **either** one makes every data modification in the database generate versions, whether or not any reader ever uses them. ## READ_COMMITTED_SNAPSHOT: statement-level versions, no code change With `READ_COMMITTED_SNAPSHOT ON`, every session running at `READ COMMITTED` reads data as it was committed when **each statement** started. Readers acquire only schema stability (`Sch-S`) locks and no row or page locks, so a long report no longer blocks writers and writers no longer block the report. Two consequences follow: 1. Two statements in the same transaction can still see different data, because each one takes its own point in time. 2. Writers keep locking. Without optimized locking, an `UPDATE` finds its rows by reading the **current** data under update (`U`) locks and then takes `X` locks; if another transaction holds a row, the `UPDATE` waits. With SQL Server 2025's optimized locking switched on, rows are qualified against the latest committed version without `U` locks, and any conflict is retried internally. In neither case does the statement fail with an update-conflict error. Setting the option requires that no other connection be in the database while the `ALTER DATABASE` runs; the database does not have to be in single-user mode. ## SNAPSHOT: transaction-level versions and Msg 3960 `ALLOW_SNAPSHOT_ISOLATION ON` alone changes no existing behaviour. A session opts in with `SET TRANSACTION ISOLATION LEVEL SNAPSHOT` **before** its transaction starts; switching a transaction that began at another level into `SNAPSHOT` makes it fail and roll back. Every read in the transaction then sees data as committed when the transaction began. Strictly, that point is the transaction's first data access after `BEGIN TRANSACTION`, which is when it receives its transaction sequence number. Writes are **optimistic**. When a `SNAPSHOT` transaction tries to update or delete a row, SQL Server checks whether another transaction modified that row and committed after the snapshot transaction started. If so, the statement fails with: - **Msg 3960**, "Snapshot isolation transaction aborted due to update conflict", and the transaction is rolled back. This detection cannot be turned off, so code that runs at `SNAPSHOT` must catch the error and retry the **whole** transaction, not just the failed statement. If the option is switched on while modification transactions are active, its state sits at `PENDING_ON` until they finish, and no `SNAPSHOT` transaction can start until the state reads `ON`. The option also has a metadata gap: if another transaction alters an object with DDL after a snapshot transaction began, the snapshot transaction gets error 3961 when it touches that object. ## Side by side | Property | `READ_COMMITTED_SNAPSHOT` | `SNAPSHOT` (via `ALLOW_SNAPSHOT_ISOLATION`) | |---|---|---| | How a session gets it | Automatically, at the default `READ COMMITTED` | `SET TRANSACTION ISOLATION LEVEL SNAPSHOT` before the transaction | | Point in time for reads | Start of each statement | Start of the transaction | | Readers' locks | `Sch-S` only | `Sch-S` only | | Write that meets a newer committed row | Waits on locks, then changes the current row | Fails with Msg 3960 | | Switching it on | No other connections in the database | Passes through `PENDING_ON` | ## What it costs and how to check - Each row can grow by up to **14 bytes** of versioning information when it is first modified or inserted, which can split full pages. - Old versions live in `tempdb`, or in the database's own persistent version store when accelerated database recovery is enabled, and a long-running transaction keeps them from being cleaned up. - `sys.databases` reports the state in `is_read_committed_snapshot_on` and `snapshot_isolation_state_desc`. A common arrangement enables both: RCSI so existing read-heavy code stops blocking, and `SNAPSHOT` for the few reports or exports whose several statements must agree with one another.

  • With READ_COMMITTED_SNAPSHOT on in SQL Server, how can one query get the old blocking read back for a single table?
    Add the `READCOMMITTEDLOCK` table hint. That read then takes shared locks and releases them when the read completes, as lock-based `READ COMMITTED` does, whatever the database option says. It is the tool for code that genuinely relied on blocking, and the hint to pair with `READPAST`, which SQL Server refuses at RCSI-based `READ COMMITTED` otherwise.
  • Why can a SQL Server SNAPSHOT transaction fail with error 3961 even though it never wrote a row?
    SQL Server does not version metadata. If another transaction changes an object with DDL, such as `ALTER TABLE` or an index operation, after the snapshot transaction started, the snapshot transaction cannot read a schema consistent with its point in time, so touching that object raises error 3961 and the transaction must be retried.

RCSI is like glancing at the last saved version of a shared spreadsheet each time you look at it. SNAPSHOT is like working all afternoon from a copy you downloaded at lunch: your view never changes, but saving a cell back fails if someone else saved that same cell after you downloaded it.

  • ALLOW_SNAPSHOT_ISOLATION ON makes every READ COMMITTED query read row versions.
  • Under READ_COMMITTED_SNAPSHOT, an UPDATE that meets a changed row fails with Msg 3960.
  • A SNAPSHOT transaction picks up new commits each time a statement starts.
  • Row versioning costs nothing until some session actually runs at SNAPSHOT.
  • RCSI removes all locking, so writers no longer block each other.

Assumes SQL Server 2025; optimized locking, new in 2025 and off by default, changes how RCSI writers qualify rows, and everything else here describes SQL Server without it.