日期:2014-05-17  浏览次数:20682 次

关于troubleshooting deadlock的一道题
题目是
1. Execute the following commands to create a base table.
USE AdventureWorks
GO
SELECT * INTO temp_Employee FROM HumanResources.Employee
GO
CREATE NONCLUSTERED INDEX IX_Employee_ManagerID ON temp_Employee(ManagerID ASC)
CREATE NONCLUSTERED INDEX IX_Employee_ModifiedDate ON temp_Employee(ModifiedDate ASC)
GO
2. Enable trace flag 1222 and use SQL Server Profile to capture trace.
3. Execute the following commands by using connection 1.
USE AdventureWorks
GO
SET NOCOUNT ON
GO
WHILE (1=1)
BEGIN
  BEGIN TRAN
    UPDATE temp_Employee SET BirthDate=GETDATE() WHERE NationalIDNumber='480951955'
    SELECT * FROM temp_Employee WHERE NationalIDNumber='480951955'
  COMMIT TRAN
END
4. Switch to connection 2, and execute the following script.
USE AdventureWorks
GO
SET NOCOUNT ON
GO
WHILE (1=1)
BEGIN
  BEGIN TRAN
    UPDATE temp_Employee SET BirthDate=GETDATE() WHERE NationalIDNumber='407505660'
    SELECT * FROM temp_Employee WHERE NationalIDNumber='407505660'
  COMMIT TRAN
END
5. What happened, why, and how to resolve?

------解决方案--------------------
方法2: 在temp_Employee表NationalIDNumber字段上建索引.