Drop a trigger after a specific date

Download PDF

 

The question of how to delete a trigger after a specific date came up.  Here is what could be done.

If you want to trigger to disappear after a specific date or time, you can just drop the trigger from inside the trigger itself. Something like this.

CREATE TRIGGER Table1_Updated
ON Table1
FOR INSERT, UPDATE
AS BEGIN
    -- do something

    -- drop the trigger after a given date
    IF (GETDATE() > '2016/05/10')
    BEGIN
        DROP TRIGGER Table1_Updated;
    END
END

If instead of dropping the trigger you just want to disable it, you could use DISABLE TRIGGER instead of DROP TRIGGER.

-Steve Stedman

Posted in TSQL Tagged with: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.