If within a Sql Server trigger I want to test if a column was not included in the UPDATE statement, is
IF NOT UPDATE(column)
the correct syntax? I've read a much older discussion suggesting this might not also work and one should use an IF UPDATE(column)...ELSE syntax, except I would not have any relevant statement to add for the first condition.
The syntax IF NOT UPDATE(column) is correct and can be verified by the following simple test, as @NoDisplayName pointed out:
CREATE TABLE dbo.Test(Id int, Foo int);
GO
INSERT INTO dbo.Test VALUES (1, 1);
GO
CREATE TRIGGER TestTrigger ON dbo.Test
AFTER UPDATE
AS
IF NOT UPDATE(Foo)
  PRINT 'Foo Not Included In Update Statement';
IF UPDATE(Id)
  PRINT 'Id Included In Update Statement';
GO
UPDATE dbo.Test SET Id = 1;
/*
output:
Foo Not Included In Update Statement
Id Included In Update Statement
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With