|
发表于 2020-1-3 23:39:01
|
显示全部楼层
举个死锁的例子给你看看:
-- 测试环境
USE tempdb
GO
CREATE TABLE t1(id int)
INSERT t1 VALUES(1)
CREATE TABLE t2(id int)
INSERT t2 VALUES(2)
GO
-- 查询窗口1中执行下面的语句
USE tempdb
GO
BEGIN TRAN
SELECT * FROM t1 WITH(TABLOCKX)
WAITFOR DELAY '00:00:10'
UPDATE t2 SET id = 1
COMMIT TRAN
GO
-- 查询窗口2中执行下面的语句
USE tempdb
GO
BEGIN TRAN
SELECT * FROM t2 WITH(TABLOCKX)
WAITFOR DELAY '00:00:10'
UPDATE t1 SET id = 1
COMMIT TRAN
GO
-- 测试完成后删除测试环境
DROP TABLE t1, t2
|
|