我在SQL Server 2008 R2下發生了以下問題而不是刪除觸發器的超時問題。只有在很多(> 6個左右)CustomFieldOption
在同一個事務中被刪除纔會出現。INSTEAD OF DELETE觸發器超時
CREATE TRIGGER dbo.[DeleteCustomFieldOptionInsteadOfTrigger] ON dbo.[CustomFieldOption] INSTEAD OF DELETE
AS
BEGIN
SET NOCOUNT ON;
UPDATE ucf SET ucf.PendingCustomFieldOptionIdValue = NULL, ucf.PendingProposedStateId = NULL
FROM UserCustomField ucf
INNER JOIN deleted d ON d.CustomFieldOptionId = ucf.PendingCustomFieldOptionIdValue
WHERE ucf.CurrentCustomFieldOptionIdValue IS NOT NULL;
SET NOCOUNT ON;
DELETE ucf FROM UserCustomField ucf
INNER JOIN deleted d ON d.CustomFieldOptionId = ucf.PendingCustomFieldOptionIdValue
WHERE ucf.CurrentCustomFieldOptionIdValue IS NULL;
SET NOCOUNT ON;
DELETE ucf FROM UserCustomField ucf
INNER JOIN deleted d ON d.CustomFieldOptionId = ucf.CurrentCustomFieldOptionIdValue;
SET NOCOUNT ON;
DELETE cfo FROM CustomFieldOption cfo
INNER JOIN deleted d ON d.CustomFieldOptionId = cfo.CustomFieldOptionId;
SET NOCOUNT OFF;
END
我認識到可能需要進一步的上下文(我會根據需要更新問題) - 我在這裏做了什麼明顯錯誤的事嗎?
爲'死鎖'和'死鎖圖表'運行一個分析器跟蹤 –
@Mitch小麥:你能更具體一點嗎?請回答:我需要做的跟蹤? – DanP
你的表是否有適當的索引,用於正在進行的'刪除'連接?這些陳述的執行計劃是什麼樣的? –