|
Let me give you an example of a deadlock:
-- test environment
USE tempdb
GO
CREATE TABLE t1 (id int)
INSERT t1 VALUES (1)
CREATE TABLE t2 (id int)
INSERT t2 VALUES (2)
GO
-Execute the following statement in query window 1
USE tempdb
GO
BEGIN TRAN
SELECT * FROM t1 WITH (TABLOCKX)
WAITFOR DELAY '00: 00: 10 '
UPDATE t2 SET id = 1
COMMIT TRAN
GO
-Execute the following statement in query window 2
USE tempdb
GO
BEGIN TRAN
SELECT * FROM t2 WITH (TABLOCKX)
WAITFOR DELAY '00: 00: 10 '
UPDATE t1 SET id = 1
COMMIT TRAN
GO
-Delete the test environment after the test is complete
DROP TABLE t1, t2 |
|