Set Trigger Order

A co-worker was telling me there is a stored procedure called sp_SetTriggerOrder supposedly in the master database. He is trying to figure out the parameters that are passed into it. However he can not find it in the master database. Does anybody know where this is located?

Who is Participating?
Scott PletcherConnect With a Mentor Senior DBACommented:
Are you looking at a 7.0 server?  As you know, that SP does not exist on 7.0.  But that SP should be there, in the master db, on a 2000 server.  If it's not, I would suggest you back up the databases and re-install SQL 2K.
Anthony PerkinsCommented:
From MSDN:
Specifies which AFTER triggers associated with a table will be fired first or last. The AFTER triggers that will be fired between the first and last triggers will be executed in undefined order.

sp_settriggerorder[@triggername = ] 'triggername'
    , [@order = ] 'value'
    , [@stmttype = ] 'statement_type'

[@triggername = ] 'triggername'

Is the name of the trigger whose order will be set or changed. triggername is sysname. If the name does not correspond to a trigger or if the name corresponds to an INSTEAD OF trigger, the procedure will return an error.

[@order = ] 'value'

Is the setting for the new trigger order. value is varchar(10) and it can be any of the following values.

Important  The First and Last triggers must be two different triggers.

Value Description
First Trigger will be fired first.
Last Trigger will be fired last.
None Trigger will be fired in undefined order.

[@stmttype = ] 'statement_type'

Specifies which SQL statement fires the trigger. statement_type is varchar(10) and can be INSERT, UPDATE, or DELETE. A trigger can be designated as the First or Last trigger for a statement type only after that trigger has been defined as a trigger for that statement type. For example, trigger TR1 can be designated First for INSERT on table T1 if TR1 is defined as an INSERT trigger. SQL Server will return an error if TR1, which has been defined only as an INSERT trigger, is set as a First (or Last) trigger for an UPDATE statement. For more information, see the Remarks section.

Return Code Values
0 (success) and 1 (failure)

There can be only one First and one Last trigger for each of INSERT, UPDATE, or DELETE statement on a single table.

If a First trigger is already defined on the table, you cannot designate a new trigger as First for the same table for the same operation (INSERT, UPDATE, or DELETE). This restriction also applies Last triggers.

As part of SQL Server replication, a First trigger can be designated on a published table; however, if a conflict with the user-defined trigger exists, the designation of the user-defined trigger must be changed to None before the table can be published.

If an ALTER TRIGGER statement changes a first or last trigger, the First or Last attribute originally set on the trigger is dropped, and the value is replaced by None. The order value must be reset with sp_settriggerorder.

If the same trigger has to be designated as the first or last order for more than one statement type, sp_settriggerorder must be executed for each statement type. Also, the trigger must be first defined for a statement type before it can be designated as the First or Last trigger to fire for the statement type.

The owner of the trigger and the table on which the trigger is defined has execute permissions for sp_settriggerorder. Members of db_owner and db_ddladmin roles in the current database, as well as the sysadmin server role can execute this stored procedure.

sp_settriggerorder @triggername= 'MyTrigger', @order='first', @stmttype = 'UPDATE'

lmredAuthor Commented:
When this syntax is placed in SQL Server Analyzer (we are using 2000), it does not run. It says it can not find this stored procedure. Even when you put master..spSetTriggerOrder it does not run.
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Anthony PerkinsCommented:
This sounds like a permissions problem.

Scott PletcherSenior DBACommented:
Be sure to code sp_SetTriggerOrder rather than spSetTriggerOrder.
lmredAuthor Commented:
The underscore has been placed in the name of the stored procedure.
Scott PletcherSenior DBACommented:
I think acperkins is right, it does sound like a permissions problem.  

You can use EM to verify that the SP exists in master, then right click on it, select Properties, click on Permissions..., and verify that Public has EXEC authority (that appears to be the default).
lmredAuthor Commented:
It does not show up in master.
Anthony PerkinsCommented:
Are you using SQL Server 7?

I believe the sp_SetTriggerOrder was introduced with SQL Server 2000.

lmredAuthor Commented:
Yes, I am looking at SQL 7. That does explain it. Thanks.

lmredAuthor Commented:
Thanks everybody for your help!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.