Transaction Isolation Levels in Microsoft SQL Server
There are four isolation levels:
Microsoft SQL Server supports all of these Transaction Isolation Levels.
SQL Server not issue shared locks while reading data. So, you can read an uncommitted transaction that might get rolled back later. This isolation level is also called dirty read. This is the lowest isolation level. It ensures only that a physically corrupt data will not be read.
This is the default isolation level in SQL Server. When it’s used, SQL Server will use shared locks while reading data. It ensures that a physically corrupt data will not be read and will never read data that another application has changed and not yet committed, but it not ensures that the data will not be changed before the end of the transaction.
When it’s used, the dirty reads and nonrepeatable reads cannot occur. It means that locks will be placed on all data that is used in a query, and another transactions cannot update the data.
When a transaction reads the same row more than one time, and between the two (or more) reads, a separate transaction modifies that row. Because the row was modified between reads within the same transaction, each read produces different values, which introduces inconsistency.
Most restrictive isolation level. When it’s used, the phantom values cannot occur. It prevents other users from updating or inserting rows into the data set until the transaction will be completed.
Phantom behavior occurs when a transaction attempts to select a row that does not exist and a second transaction inserts the row before the first transaction finishes. If the row is inserted, the row appears as a phantom to the first transaction, inconsistently appearing and disappearing.
You can set the appropriate isolation level for an entire SQL Server session by using the SET TRANSACTION ISOLATION LEVEL statement.
SET TRANSACTION ISOLATION LEVEL [ READ COMMITTED | READ UNCOMMITTED | REPEATABLE READ | SERIALIZABLE ]
You can use the DBCC USEROPTIONS statement to determine the Transaction Isolation Level currently set. This command returns the set options that are active for the current connection. This is the example:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED