While Updateting my Trigger have to ignore this ?

  • Hi ! I get the following problem.

    I have a simpel update trigger which copied me new changes in a changes-summery table. now I want in specific cases to bypass the trigger.

    Have anyone a simple idea ?

     

    Thanks in advance,

    Markus

  • You want to bypass in a specific tsql batch, or you need to bypass on a column base?

  • In a TSQL batch

  • This is what you are looking for :

    This example uses the DISABLE TRIGGER option of ALTER TABLE to disable the trigger and allow an insert that would normally violate the trigger. It then uses ENABLE TRIGGER to re-enable the trigger.

    CREATE TABLE trig_example

    (id INT,

    name VARCHAR(10),

    salary MONEY)

    go

    -- Create the trigger.

    CREATE TRIGGER trig1 ON trig_example FOR INSERT

    as

    IF (SELECT COUNT(*) FROM INSERTED

    WHERE salary > 100000) > 0

    BEGIN

    print "TRIG1 Error: you attempted to insert a salary > $100,000"

    ROLLBACK TRANSACTION

    END

    GO

    -- Attempt an insert that violates the trigger.

    INSERT INTO trig_example VALUES (1,"Pat Smith",100001)

    GO

    -- Disable the trigger.

    ALTER TABLE trig_example DISABLE TRIGGER trig1

    GO

    -- Attempt an insert that would normally violate the trigger

    INSERT INTO trig_example VALUES (2,"Chuck Jones",100001)

    GO

    -- Re-enable the trigger.

    ALTER TABLE trig_example ENABLE TRIGGER trig1

    GO

    -- Attempt an insert that violates the trigger.

    INSERT INTO trig_example VALUES (3,"Mary Booth",100001)

    GO

     

     

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

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