Setting Trigger Firing Order : Trigger order « Trigger « SQL Server / T-SQL Tutorial






7>  CREATE TABLE dbo.MyTable
8>  (TestID int NOT NULL)
9>  GO
1>
2> CREATE TRIGGER dbo.trg_i_MyTable
3> ON dbo.MyTable
4> AFTER INSERT
5> AS
6> PRINT 'I will be fired first.'
7> GO
1>
2> CREATE TRIGGER dbo.trg_i_MyTable2
3> ON dbo.MyTable
4> AFTER INSERT
5> AS
6> PRINT 'I will be fired last.'
7> GO
1>
2> CREATE TRIGGER dbo.trg_i_MyTable3
3> ON dbo.MyTable
4> AFTER INSERT
5> AS
6> PRINT '3'
7> GO
1>
2> CREATE TRIGGER dbo.trg_i_MyTable3
3>  ON dbo.MyTable
4>  AFTER INSERT
5>  AS
6>  PRINT 'I 3'
7>  GO
1>
2> EXEC sp_settriggerorder 'trg_i_MyTable', 'First', 'INSERT'
3> EXEC sp_settriggerorder 'trg_i_MyTable2', 'Last', 'INSERT'
4>
5> INSERT dbo.MyTable
6> (TestID)
7> VALUES (1)
8>
9> drop table dbo.MyTable
10>  GO

(1 rows affected)
I will be fired first.
3
I will be fired last.
1>
2>








22.10.Trigger order
22.10.1.Setting Trigger Firing Order
22.10.2.Specifying Trigger Firing Order