题目是
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?

解决方案 »

  1.   

    方法1: 在BEGIN TRAN前加: set transaction isolation level read uncommitted
      

  2.   

    方法2: 在temp_Employee表NationalIDNumber字段上建索引.
      

  3.   

    What happened?
    this:在执行批处理时出现错误。错误消息为: 引发类型为“System.OutOfMemoryException”的异常。
    why?
    死循环
    但是好像没有产生死锁。
     NationalIDNumber='480951955' 条件写的是不是有点问题。
      

  4.   

    方法2:在查询语句的后面加上with nolock我测试了一下语句,
    发现有一个问题,如果出现锁,那么使用3楼和我说的方法,如果没有出现锁,那么应该会出现System.OutOfMemoryException的异常,内存溢出,因为你使用的循环条件是while 1=1永远循环下去,内存肯定不足。