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.
Reorder trigger execution - SQL Server Tutorial
From the course: Complete Guide to Advanced SQL Server
Reorder trigger execution
When you have multiple AFTER triggers that are attached to the same table event, it might be beneficial to want them to execute in a specific sequence. This can be useful if, for example, you have one trigger that has a high likelihood of rolling back the transaction. You might want that one to run first so that your database doesn't waste time processing the other triggers before getting to the one that rolls everything back. Now, SQL Server doesn't let you set the absolute sequence for all of the triggers on the same table event, but you can specify which one will run first or which one will run last. We can take a look at how this works by creating two new tables in the KinetEcoTRG database. The first table I'll call Value, and it's going to have a column for an integer as a RowValue. The second table will be called Sequence, and will have a column called RowSequence that will store some text. So let's go ahead and create both of those tables. And now I can create a couple of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.