CREATE TRIGGER dbo.TableName_IUD ON dbo.TableName AFTER INSERT, UPDATE, DELETE AS BEGIN SET NOCOUNT ON; DECLARE @action CHAR(8) IF COLUMNS_UPDATED() <> 0 -- delete or update? BEGIN IF EXISTS (SELECT * FROM deleted) -- updated cols + old rows means action=update SET @action = 'UPDATE' ELSE SET @action = 'INSERT' -- updated columns and nothing deleted --means action=insert END ELSE -- delete BEGIN SET @action = 'DELETE' END END
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)