模拟死锁、
(1).测试用的基础数据:
CREATE
TABLE
Lock1(C1
int
default
(
0
));
CREATE TABLE Lock2(C1 int default ( 0 ));
INSERT INTO Lock1 VALUES ( 1 );
INSERT INTO Lock2 VALUES ( 1 );
CREATE TABLE Lock2(C1 int default ( 0 ));
INSERT INTO Lock1 VALUES ( 1 );
INSERT INTO Lock2 VALUES ( 1 );
2).开两个查询窗口,分别执行下面两段
sql
--
Query 1
Begin Tran
Update Lock1 Set C1 = C1 + 1 ;
WaitFor Delay ' 00:00:30 ' ;
SELECT * FROM Lock2
Rollback Tran ;
Begin Tran
Update Lock1 Set C1 = C1 + 1 ;
WaitFor Delay ' 00:00:30 ' ;
SELECT * FROM Lock2
Rollback Tran ;
--
Query 2
Begin Tran
Update Lock2 Set C1 = C1 + 1 ;
WaitFor Delay ' 00:00:30 ' ;
SELECT * FROM Lock1
Rollback Tran ;
Begin Tran
Update Lock2 Set C1 = C1 + 1 ;
WaitFor Delay ' 00:00:30 ' ;
SELECT * FROM Lock1
Rollback Tran ;