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

 

More from Stedman Solutions:

SteveStedman5
Steve and the team at Stedman Solutions are here for all your SQL Server needs.
Contact us today for your free 30 minute consultation..
We are ready to help!

Leave a Reply

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

*