• Michael L John (2/15/2014)


    You need three triggers (Ugh!); insert, update and delete.

    Actually, you don't. Just calculate whether it's an INSERT, UPDATE, or DELETE and mark a column with I, U, or D. Remember that when a trigger fires, it won't contain mixed events. It will be because of an INSERT, UPDATE, or DELETE and never a mixture.

    If I recall correctly, here's one of the faster ways to determine what the triggering action was.

    IF NOT EXISTS (SELECT TOP 1 1 FROM DELETED)

    SELECT @TriggerAction = 'I'

    ELSE IF NOT EXISTS (SELECT TOP 1 1 FROM INSERTED)

    SELECT @TriggerAction = 'D'

    ELSE SELECT @TriggerAction = 'U'

    ;

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)