the update() function in a trigger

  • I just need a quick clarification to see if I understand this function. When I have a trigger that fires on an INSERT or UPDATE, if I use the update() function within the trigger, the code within the update() test will not run if there is no value for the column I'm testing. What I'm also wondering is how NULLs factor into that. Will the INSERT of a NULL cause the update() to be true?

    Thanks!

  • The INSERT of NULL will cause UPDATE() to be true for that column, regardless of whether the NULL is explicitly supplied or implicit (by omitting it from the values list)


    Cheers,
    - Mark

  • So when will an update() be false?

  • When you UPDATE the row but not SET that particular column to any value


    Cheers,
    - Mark

  • That means that if I have a table Testing with col1, col2, col3, col4, and I did an insert like so:

    INSERT INTO Testing(col1, col2, col3, col4)

    VALUES('a', 'b','','d')

    and the update() tests col3 then it will be false?

  • No, I was saying that the INSERT INTO command will return true for update() for all columns, regardless of whether NULLS or empty strings are assigned.

    The following will return false for update() of col3:

    UPDATE Testing SET col1='a', col2='b', col4='d' WHERE .....


    Cheers,
    - Mark

  • Okay, thanks. That helps me understand it better. But , if you are using it in a trigger that fires AFTER an INSERT or UPDATE, it's useless for the insert right?

Viewing 7 posts - 1 through 6 (of 6 total)

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