IF UPDATE (column) in trigger

  • Am I right in thinking that this function does not check whether the column value will be changed, but simply whether the column is included in the update statement?

    If the latter, it is pretty useless in the situtation where updates are done by a SP that usually contains all columns whether changed or not.. (which surely is 99% of the time)?

  • Yes. This is true. As per definition of IF UPDATE (column) in books online, says that UPDATE(column) checks whether an INSERT or UPDATE action has happend (and not whether the value is changed).

    If you want to specifically check for a perticular field value changed or not then one alternative is to compare the values in <inserted> and <deleted> system tables inside trigger.

  • To know if the column actually change in a trigger you can compare the values that the CHECKSUM() functions returns in the column from the updated (in the trigger the inserted table) table and the actual table.

    If the values are different, it means that the value was modified.

  • What's the difference between comparing the checksum and comparing the actual values as Rajesh suggests?

  • Sorry, I do not have sql*server 2000 and hence cannot comment on CHECKSUM as it is availabe only in Sql*2000.

    Be aware that if you are using checksum then you cannot rely only on the checksum value since check sum can return same value for 2 different data eventhough it is very rare.

    See the link below.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_9p2h.asp

    Hope this helps.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply