Friday, August 31, 2018

SQL: create trigger

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER dbo.table_update_trigger
ON  dbo.table
FOR update
AS
BEGIN
SET NOCOUNT ON;
DECLARE @newvalue NVARCHAR(100), @id INT
 SELECT @newvalue = newvalue FROM INSERTED
SELECT @id = id FROM DELETED
UPDATGE table SET updTime = GETDATE() WHERE id = @id
END
GO

No comments: