SQL Server Performance

Triggers: IF UPDATE(col name)

Discussion in 'General Developer Questions' started by benwilson, May 23, 2005.

  1. benwilson New Member

    Hi,
    Just wondering if when you use 'IF UPDATE(col name)' in a trigger, does it just look to see if the column was included in the update statement, or does it look to see if the value of the column has changed?

    Thanks
    Ben
  2. dineshasanka Moderator

    The update() function is used to find whether a particular column has been updated or not. This function is generally used for data checks.
    Check for more info http://www.sql-server-performance.com/nn_triggers.asp

    quote:Originally posted by benwilson

    Hi,
    Just wondering if when you use 'IF UPDATE(col name)' in a trigger, does it just look to see if the column was included in the update statement, or does it look to see if the value of the column has changed?

    Thanks
    Ben
  3. benwilson New Member

    Thanks Dinesh- i have had a look at that link, but i am still not quite clear- If i have a table (Tab1) with a column (Col1) and a value 'Ben' in it and run the following statement:

    UPDATE Tab1
    SET Col1 = 'Ben'
    WHERE Col1 = 'Ben'

    so i am updating the value, but with the same data, would IF Update(Col1) in my trigger pick up this update?
  4. dineshasanka Moderator

    Yes it will pick, it won;t chekc whether the current value is as same as the new value

    quote:Originally posted by benwilson

    Thanks Dinesh- i have had a look at that link, but i am still not quite clear- If i have a table (Tab1) with a column (Col1) and a value 'Ben' in it and run the following statement:

    UPDATE Tab1
    SET Col1 = 'Ben'
    WHERE Col1 = 'Ben'

    so i am updating the value, but with the same data, would IF Update(Col1) in my trigger pick up this update?
  5. benwilson New Member

    Thanks...guess i will have to check updated and deleted to see if the value changed!

Share This Page