引用自:http://jengting.blogspot.tw/2012/06/sql.htmlhtml
根據 MSDN 將死結數量降至最低 裡的圖型模擬死結產生 ~~
sql
在 SSMS 內開啟兩個 T-SQL 查詢(兩個執行緒),利用下面語法來執行,請先執行 T-SQL 查詢 1,再執行 T-SQL 查詢 2。
步驟簡易說明:sqlserver
藉此產生一個死結。
spa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
IF OBJECT_ID(
'Supplier'
)
IS
NOT
NULL
DROP
TABLE
Supplier
IF OBJECT_ID(
'Part'
)
IS
NOT
NULL
DROP
TABLE
Part
CREATE
TABLE
Supplier
(
SPLNO
char
(5),
SPLName
char
(10),
CONSTRAINT
[PK_Supplier]
PRIMARY
KEY
CLUSTERED ([SPLNO]
ASC
)
)
CREATE
TABLE
Part
(
SPLNO
char
(5),
Product
char
(50),
CONSTRAINT
[PK_Part]
PRIMARY
KEY
CLUSTERED ([SPLNO]
ASC
,[Product]
ASC
)
)
INSERT
INTO
Supplier
VALUES
(
'00000'
,
'Microsoft'
)
INSERT
INTO
Part
VALUES
(
'00000'
,
'SQL Server 2012'
)
|
1
2
3
4
5
|
BEGIN
TRANSACTION
UPDATE
Supplier
SET
SPLName =
'Microsoft'
WHERE
SPLNO =
'00000'
-- Step 1
WAITFOR DELAY
'00:00:05'
UPDATE
Part
SET
Product =
'SQL Server 2012'
WHERE
Product =
'SQL Server 2012'
-- Step 3
COMMIT
TRANSACTION
|
1
2
3
4
5
|
BEGIN
TRANSACTION
UPDATE
Part
SET
Product =
'SQL Server 2012'
WHERE
Product =
'SQL Server 2012'
-- Step 2
WAITFOR DELAY
'00:00:05'
UPDATE
Supplier
SET
SPLName =
'Microsoft'
WHERE
SPLNO =
'00000'
-- Step 4
COMMIT
TRANSACTION
|