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 
4

1 回答 1

0

为了将来参考,我将删除的表与触发器表连接起来,以便选择 ntext 类型的列,因为这就是我的插入和更新触发器的工作方式。由于这是删除后触发器,因此我尝试选择的行已被删除。我将列从 ntext 转换为 nvarchar(max) 并摆脱了连接,现在它工作正常。

于 2013-07-22T16:48:07.983 回答