Skill 2.2.2
Preserve data integrity and consistency by using transaction isolation levels and concurrency controls
Key Concepts
READ UNCOMMITTED allows dirty reads; READ COMMITTED reads only committed data; REPEATABLE READ holds shared locks so rows read cannot change; SERIALIZABLE also prevents phantoms with range locks; and SNAPSHOT reads a consistent version of data as of the start of the transaction from row versions, without shared locks, and fails with update-conflict error 3960 if another transaction changed a row it then updates. With read committed snapshot isolation (RCSI), READ COMMITTED reads the last committed version as of each statement, so readers and writers do not block each other; RCSI and snapshot isolation are both enabled by default in Azure SQL Database.
Concurrency controls are pessimistic (locks, hints such as UPDLOCK, higher isolation) or optimistic (row versioning, or an application check of a rowversion column in the WHERE clause of an UPDATE so that a lost update affects zero rows). Optimized locking in Azure SQL Database and SQL Server 2025 locks the transaction ID rather than every row and, with RCSI, qualifies rows before locking them, which reduces lock memory and blocking. Transactions should be short and should never wait for user input.