到訪次數 | 1099047 |
訂閱次數 | 1 |
文章總數 | 1476 |
今日文章 | 0 |
回應總數 | 4 |
今日回應 | 0 |
所謂死結(Dead-lock),就是當二個或多個異動(transaction)鎖定同一資料,而且每個異動都在等待其他異動解除資源鎖定,陷入循環等待。
一、第一支transactino執行時,會先update UD1,10秒後再update UD2。
set transaction isolation level read uncommitted
begin tran
update dbo.UD1 set cID=3 where cName='aaa'
waitfor delay '00:00:10'
update dbo.UD2 set cID=3 where cName='ccc'
commit tran
二、第二支transaction執行時,先update UD2,10秒後再update UD1,因第一支transaction還在執行,所以造成死結。
set transaction isolation level read uncommitted begin tran update dbo.UD2 set cID=3 where cName='ccc' waitfor delay '00:00:10' update dbo.UD1 set cID=3 where cName='aaa' commit tran
當第一支程式還在執行時,第二支程式將出現死結訊息。