How do you attach multiple table triggers?

I have several triggers on a table that I want to save separately and would like to perforate them.

I could have only one trigger and do the logic there, but I was wondering if there is a simpler / more logical way to accomplish this due to the fact that it has a given order?

+5
source share
4 answers

Use sp_settriggerorder. You can specify that the first and last trigger fire depending on the operation.

sp_settriggerorder on MSDN

:
. DML
, uSalesOrderHeader , UPDATE Sales.SalesOrderHeader.

USE AdventureWorks;
GO
sp_settriggerorder 
    @triggername= 'Sales.uSalesOrderHeader', 
    @order='First', 
    @stmttype = 'UPDATE';

. DDL
, ddlDatabaseTriggerLog , ALTER_TABLE AdventureWorks.

USE AdventureWorks;
GO
sp_settriggerorder 
    @triggername= 'ddlDatabaseTriggerLog', 
    @order='First', 
    @stmttype = 'ALTER_TABLE', 
    @namespace = 'DATABASE';
+6

.

+1

sp_settriggerorder, .

, , . , , , . , - / . , , , , , .

+1

Rememebr, if you change the order of the triggers, someone else may come back later and change it again. And where would you document what the trigger order should be, so the service developer should not mess with the order or something breaks? If a specific task needs to be performed by two trigger tasks, the only safe route is to put them in the same trigger.

0
source

All Articles