Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Discover why SQL Server WITH (NOLOCK) causes dirty reads, duplicated rows, and query errors. Learn how Read Committed Snapshot Isolation fixes locks.
Quick answer
The WITH (NOLOCK) hint in SQL Server instructs the database engine to run queries under the READ UNCOMMITTED isolation level. While it prevents queries from being blocked by write locks, it can return uncommitted dirty data, duplicate rows, skip records during index page splits, and throw allocation scan errors.
FAQs
Does WITH (NOLOCK) make queries faster?
It avoids waiting for exclusive locks, but does not optimize query execution plans or reduce disk I/O. Proper indexing and query design provide far greater performance gains.
Can WITH (NOLOCK) cause an error in SQL Server?
Yes. SQL Server can throw Error 601 when data moves rapidly due to index page splits or schema changes during a scan.
What is the difference between NOLOCK and SNAPSHOT isolation?
NOLOCK reads dirty uncommitted data that may be rolled back. SNAPSHOT isolation uses row versioning in tempdb to read committed historical records without blocking.
Does RCSI require changing application query code?
No. Once enabled on the database, standard SELECT queries automatically use row versioning without modifying SQL code.
Build fast text search directly in PostgreSQL without external search engines. Master to_tsvector, to_tsquery, relevance ranking with ts_rank, and GIN indexes.
Paste your SQL Server (T-SQL) query into sqlfmt — format, validate against real SQL Server (T-SQL) grammar, and catch keyword typos free in your browser.
Few SQL Server patterns are as widespread or misunderstood as the WITH (NOLOCK) table hint. Many developers add WITH (NOLOCK) to every SELECT query as an automatic reflex to prevent blocking on busy production databases. What seems like a magic speed boost actually bypasses essential engine safety mechanisms.
Running queries with WITH (NOLOCK) causes dirty reads, phantom records, missing data, and duplicated rows. In financial, inventory, and reporting applications, silent data corruption can go unnoticed for months. Understanding how SQL Server locking works reveals why modern snapshot isolation is the correct alternative.
What WITH (NOLOCK) actually does to isolation levels
In SQL Server, WITH (NOLOCK) is functionally identical to setting the transaction isolation level to READ UNCOMMITTED. Under standard READ COMMITTED isolation, SQL Server acquires shared locks (S locks) when reading rows, which prevents it from reading data currently locked by exclusive locks (X locks) held by active UPDATE or INSERT transactions.
When you append WITH (NOLOCK), the query engine ignores shared locks completely. It does not wait for active transactions to commit or roll back. It reads raw data pages directly from memory or disk, regardless of whether another transaction is in the middle of modifying them. Learn more about transaction mechanics in our guide to SQL transactions and ACID properties.
The three primary failure modes of NOLOCK
Most developers understand that NOLOCK allows dirty reads. However, dirty reads are only the most visible symptom. The mechanical side-effects of scanning unlocked pages are far more dangerous.
1. Dirty reads and phantom updates
If a background process begins a transaction to update 10,000 account balances, updates 5,000 of them, and then encounters an error that forces a ROLLBACK, any NOLOCK query running concurrently will read the modified, uncommitted balances. Your reporting query produces numbers that never legally existed in the database.
2. Skipped rows and duplicate rows from page splits
SQL Server organizes B-tree indexes into 8KB pages. When an update or insert causes an index page to split, SQL Server allocates a new page, moves approximately half the rows to the new page, and updates the double-linked list connecting pages. If an index scan reading with NOLOCK reaches a page during a split, it can read rows twice or skip an entire page of records completely.
3. Error 601: could not continue scan with NOLOCK
When a table structure changes or high concurrency causes rapid allocation changes, a NOLOCK query can encounter Msg 601, Level 12, State 1: Could not continue scan with NOLOCK due to data movement. The query fails abruptly and must be restarted.
Demonstrating a dirty read in T-SQL
You can observe dirty reads directly by opening two query windows in SQL Server Management Studio or Azure Data Studio.
Simulating dirty reads in SQL Server
-- Session 1: Run uncommitted updateBEGIN TRANSACTION;UPDATE AccountsSET Balance = Balance - 5000.00WHERE AccountId = 1042;-- Do not commit yet...-- Session 2: Read with NOLOCKSELECT AccountId, BalanceFROM Accounts WITH (NOLOCK)WHERE AccountId = 1042;-- Reads the balance minus $5,000!-- Session 1: Rollback transactionROLLBACK TRANSACTION;-- Session 2: Re-read with standard READ COMMITTEDSELECT AccountId, BalanceFROM AccountsWHERE AccountId = 1042;-- Balance is restored. Session 2 had processed false data.
According to Microsoft Learn table hints documentation, Microsoft explicitly warns that using READ UNCOMMITTED can cause inconsistent query results and should be avoided for transactional decision systems.
The modern solution: Read Committed Snapshot Isolation (RCSI)
You do not need to choose between blocking and dirty reads. SQL Server has supported row versioning since SQL Server 2005 through Read Committed Snapshot Isolation (RCSI). Under RCSI, readers do not block writers, and writers do not block readers.
When an UPDATE modifies a row, SQL Server copies the previous committed version of the row to tempdb. When a SELECT query runs, it reads the committed snapshot from tempdb without waiting for the writer to commit. Readers always see consistent, committed data without blocking active updates.
Once RCSI is enabled at the database level, all standard SELECT queries benefit automatically. You can remove WITH (NOLOCK) hints entirely, eliminating dirty reads while keeping read and write concurrency high. Refer to Microsoft documentation on ALTER DATABASE SET options for implementation requirements.
Actionable checklist for eliminating NOLOCK hints
Audit the codebase: search repository queries for WITH (NOLOCK) and (NOLOCK) aliases.
Monitor tempdb capacity: ensure tempdb is sized properly with multiple data files on fast NVMe storage before enabling RCSI.
Enable RCSI in staging: test application workloads with READ_COMMITTED_SNAPSHOT ON to observe row versioning overhead.
Replace report query hints: if specific long-running reports cannot use RCSI, use SNAPSHOT isolation instead of NOLOCK.
Fix underlying indexing: analyze slow queries that developers attempted to fix with NOLOCK to resolve missing indexes or deadlocks.
Enforce CI linting: add pull request checks to prevent new NOLOCK hints from entering production code.
Wrapping up
Using WITH (NOLOCK) in SQL Server introduces subtle bugs, inaccurate reporting, and missing records. Enabling Read Committed Snapshot Isolation provides non-blocking reads while guaranteeing transactional integrity. When preparing database scripts and complex T-SQL queries for review, format your code with sqlfmt to maintain clean syntax standards across your team.