我的数据库中的一个表上有一个删除触发器,该触发器应该将行插入到“审计”表中,但是当我从触发器表中删除行时,它们不会显示在审计表中。我有插入和更新触发器遵循同样的格式,可以正常工作,但我似乎无法让这个工作正常。这是触发器:
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