Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ================================================
- -- 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
- DROP TRIGGER dbo.TestBase_change
- GO
- -- =============================================
- -- Author: RDEM
- -- Create date:
- -- Description:
- -- =============================================
- CREATE TRIGGER dbo.TestBase_change
- ON dbo.TestBase
- AFTER INSERT,DELETE,UPDATE
- AS
- 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 dbo.TestBaseVersioningExp(row_type,Id,NewDescription,OldDescription,CreatedAt)
- SELECT 'inserted',a.Id,a.Description,'',a.CreatedAt
- FROM inserted a
- WHERE NOT EXISTS (SELECT * FROM deleted WHERE id =a.Id )
- UNION ALL
- SELECT 'deleted',a.Id,'' ,a.Description,a.CreatedAt
- FROM deleted a
- WHERE NOT EXISTS (SELECT * FROM inserted WHERE id =a.Id )
- UNION ALL
- SELECT 'updated',a.Id,a.Description,b.Description,a.CreatedAt
- FROM inserted a JOIN deleted b ON a.Id=b.Id
- WHERE EXISTS (SELECT * FROM deleted WHERE id =a.Id )
- END
- GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement