Skip to navigation
A trigger example for mssql
26.03.14
update trigger for mssql USE [MYDB] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER TRIGGER [dbo].[customer_update] ON [MYDB].[dbo].[customer] AFTER INSERT,UPDATE AS IF NOT UPDATE() RETURN DECLARE @cid int, @date int, @kind nvarchar(10),@okind nvarchar(10) BEGIN SET @cid = (SELECT TOP 1 lkh_customer_code FROM inserted) SET @date = DATEDIFF(s, '19700101', GETDATE()) SET @kind = (SELECT TOP 1 lkh_customer_kind FROM inserted) SET @okind = (SELECT TOP 1 lkh_customer_kind FROM deleted) INSERT INTO [dbo].zz_customer_history(customer_id,date,kind_from,kind_to) VALUES(@cid,@date,@okind,@kind) END
http://msdn.microsoft.com/en-us/library/ms189799.aspx
Reply
Anonymous
Information Epoch 1736564392
Make every program a filter.
Home
Notebook
Contact us