• timwell - Friday, August 10, 2018 7:39 AM

    sipas - Friday, August 10, 2018 5:40 AM

    I thought UPDATE() was meant to tell you if an attempt was made to update the column, so it would be TRUE even if the update is unsuccessful - not sure though...

    According to the remarks section in the reference provided:

    UPDATE() returns TRUE regardless of whether an INSERT or UPDATE attempt is successful.

    The confusion is because UPDATE is unintuitive. It returns true if a column name was named in an an update statement regardless of whether the value has changed.

    So if column x has a value of 1 and the command UPDATE SET x = 1 is run, UPDATE will return true even though the value hasn't changed.

    Theory wise this is probably the correct. In practice, most people are usually only interested in whether the value has changed from the previous value. So in the example above, we don't care if the UPDATE statement set the value of x to 1. We care if the value of x has changed to something other than 1.

    The only way to determine that is to compare the inserted and deleted tables.