Transactions are used to ensure data integrity and manage concurrent access in SQL Server. There are two types of transactions: implicit, which automatically commit after each statement, and explicit, which require BEGIN, COMMIT, or ROLLBACK statements. Transactions have ACID properties including atomicity, consistency, isolation, and durability. Isolation levels like read committed and serializable control how transactions see concurrent data modifications. Snapshot isolation is an alternative to locking that uses row versioning to provide consistency.
1. SQL Server Transaction Management Denise McInerney San Francisco SQL Server User Group April 9, 2008
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18. Isolation Levels Summary From Books Online “Managing Concurrent Data Access” No No No Serializable Yes No No Repeatable Read Yes Yes No Read committed Yes Yes Yes Read Uncommitted Phantom Rows Non-Repeatable Read Dirty Read Isolation Level
19.
20.
21. Snapshot Isolation Summary From Books Online “Row Versioning-based Isolation Levels in the Database Engine” Uses row versions to select rows to update. Tries to acquire an exclusive lock on the actual data row to be modified, and if the data has been modified by another transaction, an update conflict occurs and the snapshot transaction is terminated. Reverts from row versions to actual data to select rows to update and uses update locks on the data rows selected. Acquires exclusive locks on actual data rows to be modified. No update conflict detection. How updates are handled. Integrated support. Cannot be disabled. None. Update conflict detection. All data that was committed before the start of each transaction. All data that was committed before the start of each statement. The version of data read by statements. Requires the execution of SET TRANSACTION ISOLATION LEVEL to specify the SNAPSHOT isolation level before the start of the transaction. Use the default read-committed isolation level, or run the SET TRANSACTION ISOLATION LEVEL statement to specify the READ COMMITTED isolation level. This can be done after the transaction starts. How a session requests the specific type of row versioning. ALLOW_SNAPSHOT_ISOLATION READ_COMMITTED_SNAPSHOT The database option that must be set to ON to enable the required support. Snapshot isolation level Read-committed snapshot isolation level Property