We help IT Professionals succeed at work.

How would i merge 4 Triggers to fire in sequence?

bmanmike39
bmanmike39 asked
on
Medium Priority
216 Views
Last Modified: 2007-01-01
Can someone show me a sample of  how to merge my 4 triggers, to fire in sequence.

It’s kind of urgent that i find a solution to this problem ASAP.

I’m just learning Tsql, and know only the basics.

Any help would be appreciated!
Comment
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
well, simply merge the code of the 4 triggers in the order you want to run it...
CERTIFIED EXPERT

Commented:
sp_settriggerorder
CERTIFIED EXPERT
Commented:
to set the trigger firing order

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

or if its merging everything together, is it after triggers for different actions

if so as angel suggested

CREATE TRIGGER trig2
ON table
FOR INSERT, UPDATE
AS
   ur logic

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
My understanding of the sp_settriggerorder is that i can only set the first and last trigger, and the other will fire in undefined order.
I need each to fire in defined order to update.  I thought the article also said setting the first trigger to update would cause a error.

Is my code correct? Is what i should would do?

CREATE TRIGGER   TriggerAll
ON    table2
FOR   UPDATE
AS
 
sp_settriggerorder @Triggeroder1= 'Trigger1', @order='first'
sp_settriggerorder @Triggeroder2= 'Trigger2',
sp_settriggerorder @Triggeroder= 'Trigger3',
sp_settriggerorder @Triggeroder= 'Trigger4, @order='last'
CERTIFIED EXPERT

Commented:
u r right

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.
CERTIFIED EXPERT

Commented:
is all the triggers for update action on table2 ?

if so they can be merged as angel suggested

Author

Commented:
Yes

I do not know how to merge the updates,  does that mean just put the queries in the order they must happen in the one trigger, one after another?

Commented:
<<does that mean just put the queries in the order they must happen in the one trigger, one after another?>>

Yes.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.