Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "IF NOT UPDATE(column)" valid syntax?

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.

like image 956
mdisibio Avatar asked Oct 28 '25 03:10

mdisibio


1 Answers

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
*/
like image 55
mdisibio Avatar answered Oct 29 '25 20:10

mdisibio