How to set a After Delete Trigger with SQL Server 2008?

I need to save, in a table, data of the last record deleted.

I am using After DELETE when in the the table one of the columns, which is Booking = 0'


USE [WMS_KRAFT750_PROD]
GO
/****** Object:  Trigger [WMS.Storage].[StockUnitPositionLogger]    Script Date: 10/24/2011 10:17:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:            <Klisch Michal>
-- Create date: <Create Date,,>
-- Description:      <Description,,>
-- =============================================


      CREATE TRIGGER [WMS.Storage].[StockUnitPositionLogger]
            ON  [WMS.Storage].[StockUnitPosition]
       AFTER DELETE
      AS       
      IF EXISTS (SELECT Id FROM [WMS.Storage].[StockUnitPosition]
             where Booking = 0)
      BEGIN
            SET NOCOUNT ON;
            declare @inputbuffer table (EventType nvarchar(30),Parameters int,EventInfo nvarchar(4000))      
            insert into @inputbuffer exec('dbcc inputbuffer('+@@Spid+')')
            insert into LogTable
            select GETDATE(), EventInfo, 1 from @inputbuffer
      END
iscivanomarAsked:
Who is Participating?
 
Scott PletcherConnect With a Mentor Senior DBACommented:
CREATE TRIGGER [WMS.Storage].[StockUnitPositionLogger]
            ON  [WMS.Storage].[StockUnitPosition]
       AFTER DELETE
      AS      
      SET NOCOUNT ON;
      IF EXISTS (SELECT Id FROM deleted where Booking = 0)
      BEGIN
            insert into LogTable
            select GETDATE(), ...other columns...
            FROM deleted
            WHERE Booking = 0
      END --IF
 
0
 
iscivanomarAuthor Commented:
Thank you, it work perfectly.

Have a nice day.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.