question

Matt Whitfield avatar image
Matt Whitfield asked

How can I specify the order in which triggers run?

Seeder question: I have four triggers which run after an INSERT statement on a particular table - is there any way that I can set the order in which the triggers run? Are there any limitations?

t-sqltrigger
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Raj More avatar image
Raj More answered

You can only specify FIRST and LAST on the order of triggers using sp_SetTriggerOrder.

http://technet.microsoft.com/en-us/library/ms186762.aspx

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David 1 avatar image
David 1 answered

My first reaction would be that 4 insert triggers is much too many. One trigger is too many most of the time. Triggers are a pain to maintain, they obfuscate code and hurt performance. I would use them only as a last resort.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Michael Villegas avatar image
Michael Villegas answered

I would recommend that you consolidate all the logic of the 4 triggers into 1 trigger and then you would have control over the order of execution of the sentences. I also agree with dportas, triggers are a pain, you should try to avoid them.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.