Temporarily disabling a trigger

  • I have a trigger on a table (for insert, update) to enforce some business rule. I only need to check for the value of one field of the table, the values of the other columns don't matter.

    Ts there anyway to make the trigger work only when the update is on a specified column??

    During the work day the users only access this table for inserting or updating only one row at a time, so trigger has a nice response time.

    At the end of the day however, the apliccation needs to make some massive update not concerning the the field checked by the trigger, but i can't see how to disable the trigger to avoid unnecesary checking on every update.

    Cheers,

    felix

     

  • Felix,

    To make a trigger carry out an action only when a specific column is updated, try the IF UPDATE (columnName) syntax:

    CREATE TRIGGER tr_MyTrigger

    ON MyTable

    FOR UPDATE

    AS

       IF UPDATE (colname)

          BEGIN

             all your trigger code in here

          END

    ...

    That way, the trigger only carries out the coded action when your particular column is touched.

    Another option, though perhaps more dangerous, is to disable the trigger in the evening when the mass processes run.  I would only do this if you can guarantee that no regular user is able to update the table during that time period.

    Hope this helps,

    Scott Thornburg

  • Thanx a lot, it's exactly what i need.

    Cheers,

    Felix

  •  

    I found this kb article on using the IF update(column name)

    http://support.microsoft.com/kb/64238/EN-US/

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

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