-- ================================================ -- 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