How to know which type of Trigger is fired

  • There is a trigger on a table for Insert,Update and delete operations like:

    ALTER TRIGGER [dbo].[UpdateRouteMaster]

    ON [dbo].[TransportAllotment]

    AFTER INSERT,DELETE,UPDATE

    Inside trigger i want to know what type of operation is going on..

    like:

    if(insertion) //Dont know exact syntax

    do processing 1

    if(deletion) Dont know exact syntax

    do processing 2

    if(updation) Dont know exact syntax

    do processing 3

    Can u please help me in writing exact syntax

  • You can use EXISTS to check the inserted and deleted tables.

    If the trigger was fired by an insert, only the inserted table will be populated

    If the trigger was fired by an update, both the inserted and deleted tables will be populated

    If the trigger was fired by a delete, only the deleted table will be populated.

    That said, if you're doing something completely different for insert than for update than for delete, write three triggers, one just for insert, one just for update and one just for delete.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

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