Tuesday, December 8, 2009

MSSQL trigger

-- ================================================
-- Template generated from Template Explorer using:
-- Create Trigger (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- See additional Create Trigger templates for more
-- examples of different Trigger statements.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date,,>
-- Description:    <Description,,>
-- =============================================
CREATE TRIGGER   trig_delete_input_msc
   ON   Input_MSC
   AFTER  DELETE
AS
DECLARE @deletedRows bigint
select @deletedRows=(select count(*) from    Deleted)
DECLARE @deletedPeriod varchar(50)
select @deletedPeriod=('input msc has no period')
DECLARE @action varchar(50)
select @action='Delete'
DECLARE @tableName varchar(50)
select @tableName='Input_MSC'

BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for trigger here
    insert into iscm_log values (@tableName, @action, @deletedRows, getdate(), @deletedPeriod )

END
GO

No comments: