Friday, 30 January 2015

How to track column value change in sql server


CREATE TRIGGER [dbo].[TGRName]
ON [dbo].[TableName]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
IF (UPDATE([ColumnName]))

INSERT INTO [TableName]([Columns]....)
Select distinct [Columns]....
from INSERTED I
INNER JOIN Deleted D ON D.Id= I.Id
WHERE I.[ColumnName] <> D.[ColumnName]

SET NOCOUNT OFF

END