sql server trigger execution order

Veröffentlicht am: 11 September 2015
auf dem Kanal: kudvenkat
56,944
257

sql server set trigger order
sp_settriggerorder in sql server
sp_settriggerorder example
exec sp_settriggerorder

In this video we will discuss how to set the execution order of triggers using sp_settriggerorder stored procedure.

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

Server scoped triggers will always fire before any of the database scoped triggers. This execution order cannot be changed.

In the example below, we have a database-scoped and a server-scoped trigger handling the same event (CREATE_TABLE). When you create a table, notice that server-scoped trigger is always fired before the database-scoped trigger.

CREATE TRIGGER tr_DatabaseScopeTrigger
ON DATABASE
FOR CREATE_TABLE
AS
BEGIN
Print 'Database Scope Trigger'
END
GO

CREATE TRIGGER tr_ServerScopeTrigger
ON ALL SERVER
FOR CREATE_TABLE
AS
BEGIN
Print 'Server Scope Trigger'
END
GO

Using the sp_settriggerorder stored procedure, you can set the execution order of server-scoped or database-scoped triggers.

sp_settriggerorder stored procedure has 4 parameters
@triggername - Name of the trigger
@order - value can be First, Last or None. When set to None, trigger is fired in random order
@stmttype - SQL statement that fires the trigger. Can be INSERT, UPDATE, DELETE or any DDL event
@namespace - Scope of the trigger. Value can be DATABASE, SERVER, or NULL

EXEC sp_settriggerorder
@triggername = 'tr_DatabaseScopeTrigger1',
@order = 'none',
@stmttype = 'CREATE_TABLE',
@namespace = 'DATABASE'
GO

If you have a database-scoped and a server-scoped trigger handling the same event, and if you have set the execution order at both the levels. Here is the execution order of the triggers.
1. The server-scope trigger marked First
2. Other server-scope triggers
3. The server-scope trigger marked Last
4. The database-scope trigger marked First
5. Other database-scope triggers
6. The database-scope trigger marked Last

Text version of the video
http://csharp-video-tutorials.blogspo...

Slides
http://csharp-video-tutorials.blogspo...

All SQL Server Text Articles
http://csharp-video-tutorials.blogspo...

All SQL Server Slides
http://csharp-video-tutorials.blogspo...

Full SQL Server Course
   • SQL Server tutorial for beginners in arabic  

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenka...

All Dot Net and SQL Server Tutorials in Arabic
   / kudvenkatarabic  


Auf dieser Seite können Sie das Online-Video sql server trigger execution order mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer kudvenkat 11 September 2015 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 56,944 Mal angesehen und es wurde von 257 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!