我在桌子上發現了很多死鎖。 它是SQL Server 2005中如何找出表格具有哪種類型的鎖定?
即得到錯誤的SP執行以下操作
Delete From
EmployeeAccrualAdj
Where
EmployeeID = @iEmployeeID and
SchemeCode = @sSchemeCode and
AdjTypeCode = @sAdjTypeCode and
EffectiveDate >= @dtDateFrom
我想,如果數據庫正在做行,頁或表鎖時刪除工作了呢?
而且,我想重新寫的SP到
declare @ToDelete table (id int IDENTITY(1,1),
AccrualAdjID int NOT NULL)
insert into @ToDelete
SELECT
AccrualAdjID
FROM
EmployeeAccrualAdj
Where
EmployeeID = @iEmployeeID and
SchemeCode = @sSchemeCode and
AdjTypeCode = @sAdjTypeCode and
EffectiveDate >= @dtDateFrom
DECLARE @iCount int, @iMax int
SELECT
@iCount = 1, @iMax = MAX(id)
FROM
@ToDelete
declare @iAccrualAdjID int
WHILE @iCount <= @iMax
BEGIN
select @iAccrualAdjID = AccrualAdjID FROM @ToDelete WHERE id = @iCount
DELETE FROM EmployeeAccrualAdj
WHERE @iAccrualAdjID = AccrualAdjID
SET @iCOunt = @iCount + 1
END
通過行用途不同循環被刪除,刪除它們一次一個。
我想這不會有任何區別,如果有行鎖定,但會如果有頁或表鎖定 你們都認爲?
我們得到的錯誤信息是 事務(進程ID 51)在lock |通信緩衝區資源與另一個進程並被選爲死鎖受害者。重新運行交易。 (執行存儲過程時出錯:Employee_AccrualAdjustments_Delete @iEmployeeID = 510337,@sSchemeCode =''SAH'',@sAdjTypeCode =''A'',@dtDateFrom =''2008-09-20T00:00:00'')' – 2010-02-10 23:10:00