From the course: Complete Guide to Advanced SQL Server

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Enable and disable triggers

Enable and disable triggers

Once created, triggers are automatically enabled and will start firing as soon as they're triggered. Database developers can choose to disable triggers to keep them from executing, without having to completely remove them from the database. Triggers can then be re-enabled later with a simple TSQL command. Let's take a look by creating a new table called Inventory. And then I'm going to create a trigger on that table called InventoryMessage. And it's going to be an AFTER INSERT trigger. So anytime this table receives an INSERT command, we're going to simply print a line that says, "The trigger has fired!" And we'll send that to the Messages window. So I'm going to highlight lines one through 16 and execute them to create the table and then create the trigger on that table. Now, let's insert a row into the table. I'll run line 18 through 21. This inserts the row into the table and it fires the trigger And I get my custom message here. Now, when a trigger is enabled, there's no way to…

Contents