Avoiding Phantom Reads
Avoiding Phantom Reads
systems) when a transaction reads a set of rows matching a condition, but another transaction inserts,
updates, or deletes rows that affect the result of the original query. This causes the result of the original
query to change if it is re-executed within the same transaction.
· Instead of locking, SQL Server uses row versioning to provide a consistent snapshot of the data
for the duration of the transaction.
· This prevents phantom reads without blocking other transactions
Serializable
Serializable is an extreme measure to demand total control of the range of rows being modified. It will not read un-
committed and it will not allow other transactions to read data that it is modifying. As such, it requires exclusive locks,
causing other transactions to wait for it to complete. This also prevents other rows from being added to the set of
records, preventing what is known as a phantom read.
Serializable Isolation (Layman’s Terms)
Serializable is the strictest isolation level. It ensures that transactions behave as though they are hap-
pening one after the other, never overlapping. You’ll never see incomplete data or changes that might
affect your work, and other transactions can’t make any changes that would interfere with what you’re
doing. This prevents any type of "phantom reads," meaning you won’t see new data that shows up dur-
ing your transaction.