Does anyone know how SQL Server determines the order triggers (of same type, i.e. before triggers) are executed. And is there any way of changing this so that I can specify the order I want. If not, why not.
Thanks.
The First and Last triggers must be two different triggers. First : Trigger is fired first. Last : Trigger is fired last.
Triggers (one or more) are implicitly fired (executed) by Oracle when a triggering event occurs, no matter which user is connected or which application is being used. Figure 20-1 shows a database application with some SQL statements that implicitly fire several triggers stored in the database.
SQL Server allows multiple triggers on the table for the same event and there is no defined order of execution of these triggers. We can set the order of a trigger to either first or last using procedure sp_settriggerorder. There can be only one first or last trigger for each statement on a table.
Database Triggers vs. Database triggers are defined on a table, stored in the associated database, and executed as a result of an INSERT, UPDATE, or DELETE statement being issued against a table, no matter which user or application issues the statement.
Using SetTriggerOrder is fine, but if your code depends on a specific sequence of execution, why not wrap all your triggers into stored procedures, and have the first one call the second, the second call the third, etc.
Then you simply have the first one execute in the trigger.
Someone in the future will be grateful that they didn't have to dig around in a system table to determine a custom execution sequence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With