Given this simple example trigger:
CREATE TRIGGER example_update
ON example_table
FOR UPDATE
AS BEGIN
if update(someColumn) begin
update example_table SET last_update_date = GETDATE() WHERE id IN (SELECT id FROM inserted);
end
END
If the old value of someColumn and the new value of someColumn are equal, does update(someColumn) return true or false? For example, if I run these two SQL statments:
UPDATE example_table SET someColumn=1;
UPDATE example_table SET someColumn=1;
Does the second statement fire the if block in my trigger?
Also, am I correct in my presumption that if I execute this:
UPDATE example_table SET otherColumn=1;
then update(someColumn) in my trigger will return false.
I apologize if this is a repeat: the fact the the function is called update has flooded my search results with update statments (which are very different from the update function), and has made it very difficult for me to pin down this behavior.
The
UPDATE()function does not discriminate whether the value has changed or not, only that the column was updated. To do this, you should compare the values in theinsertedanddeletedpseudo-tables.