1076
Part VIII: Performance Tuning and Optimization
USE AdventureWorks2012SET TRANSACTION ISOLATION LEVEL
READ COMMITTEDBEGIN TRANSACTION
SELECT Name
FROM HumanResources.Department
WHERE DepartmentID = 1Result:Name
------------------------
EngineeringTransaction 1 now updates the department name to Non-Repeatable Read:-- Transaction 1
USE AdventureWorks2012;
UPDATE HumanResources.Department
SET Name = 'Non-Repeatable Read'
WHERE DepartmentID = 1;Transaction 2 reads the row again. If it sees the value updated by transaction 2, it results
in a nonrepeatable read:SELECT Name
FROM HumanResources.Department
WHERE DepartmentID = 1COMMIT TRANSACTIONResult:Name
------------------------
Non-Repeatable ReadSure enough, transaction 2’s read was not repeatable.Preventing the Fault
Rerunning the same scripts with transaction 2’s transaction isolation level to
repeatable read will result in a different behavior (assuming an unaltered copy of
AdventureWorks2012):-- Transaction 2USE AdventureWorks2012
SET TRANSACTION ISOLATION LEVELc47.indd 1076c47.indd 1076 7/31/2012 10:23:31 AM7/31/2012 10:23:31 AM
http://www.it-ebooks.info