Suppose you have one table and you want to put two triggers to be fired on this table.
This trigger we can implement for DDL (CREATE) AND DML(Insert , Update and Delete)
CREATE TABLE DBO.MYTABLE
(MYNAME VARCHAR(10))
Now creating trigger
Create Trigger TrMyTable1 on MyTable
for insert
As
Set Nocount On
Begin
Print 'I am in TrMyTable1'
End
Create Trigger TrMyTable2 on MyTable
for insert
As
Set Nocount On
Begin
Print 'I am in TrMyTable2'
End
Now we suppose we want second trigger (TrMyTable2) to fire first then we need to set order
Exec sp_settriggerorder @triggername = 'TrMyTable2',
@order = 'first',
@stmttype = 'insert',
@namespace = null
GO
Exec sp_settriggerorder @triggername = 'TrMyTable1',
@order = 'last',
@stmttype = 'update',
@namespace = null
GO
This trigger we can implement for DDL (CREATE) AND DML(Insert , Update and Delete)
CREATE TABLE DBO.MYTABLE
(MYNAME VARCHAR(10))
Now creating trigger
Create Trigger TrMyTable1 on MyTable
for insert
As
Set Nocount On
Begin
Print 'I am in TrMyTable1'
End
Create Trigger TrMyTable2 on MyTable
for insert
As
Set Nocount On
Begin
Print 'I am in TrMyTable2'
End
Now we suppose we want second trigger (TrMyTable2) to fire first then we need to set order
Exec sp_settriggerorder @triggername = 'TrMyTable2',
@order = 'first',
@stmttype = 'insert',
@namespace = null
GO
Exec sp_settriggerorder @triggername = 'TrMyTable1',
@order = 'last',
@stmttype = 'update',
@namespace = null
GO
No comments:
Post a Comment