0
我在我的數據庫中的表中有一個刪除觸發器,應該是將行插入到「審計」表中,但是當我從觸發器表中刪除行時,它們不會顯示在審計中表。我有插入和更新觸發器遵循這種相同的格式,工作正常,但我似乎無法得到這一個工作。這裏是觸發:刪除觸發器不工作
USE [OutageDev]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[tr_audOutageSummaryDelete]
ON [dbo].[Outage Summary]
AFTER DELETE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO dbo.[Outage Summary Audit]
(OutageSummaryID,
Dispatcher,
/*Removed columns for brevity*/
StateEmergency,
Comment,
AuditDateTime,
AuditUser,
AuditAction)
SELECT d.OutageSummaryID,
d.Dispatcher,
/*Removed columns for brevity*/
d.StateEmergency,
t.Comment,
GETDATE(),
SUSER_SNAME(),
'DELETE'
FROM deleted d
JOIN [Outage Summary] t
ON d.OutageSummaryID = t.OutageSummaryID
END
看起來它應該工作。行是否與刪除的記錄中的'OutageSummaryID'完全匹配?如果是的話,觸發器肯定啓用? –
感謝您的編輯。觸發器已啓用。 OutageSummaryID是表格的PK,所以我認爲他們必須匹配。 – philthyfool
哦,我明白了。我沒有意識到這個連接回到了基礎表上。你根本不應該有'JOIN'。只需使用'd.Comment'而不是't.Comment'並擺脫連接。 –