I will try to explain my problem as basic as possible:
I have two tables: Foo and Foo_Audit.
On row update I want to copy the row to the Foo_Audit table, but only if the value of Foo.Bar or Foo.Qux changes. Foo.Baz needs to be ignored.
Here is my code:
CREATE TRIGGER tr_Foo_Modified ON Foo FOR UPDATE AS SET NOCOUNT ON DECLARE @rowCount int SELECT @rowCount = COUNT(*) FROM (SELECT Bar, Qux FROM inserted EXCEPT SELECT Bar, Qux FROM deleted) #TempTable IF (@rowCount > 0) BEGIN INSERT INTO Foo_Audit(Bar, Qux, Baz) SELECT Bar, Qux, Baz FROM Foo END Everything works perfectly fine, if I test it by updating just one row at the time. But when multiple rows are updated at the same time (~400), it sometime adds the same row multiple times to the Foo_Audit table and it adds the row even if the value of Foo.Bar or Foo.Qux hasn't changed.
Does anyone know, how to make my code work on multiple row-updates at the same time? And by the same time I mean same millisecond.