Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

How would i merge 4 Triggers to fire in sequence?

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!
0
bmanmike39
Asked:
bmanmike39
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
well, simply merge the code of the 4 triggers in the order you want to run it...
0
 
Gautham JanardhanCommented:
sp_settriggerorder
0
 
Gautham JanardhanCommented:
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
0
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

 
bmanmike39Author 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'
0
 
Gautham JanardhanCommented:
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.
0
 
Gautham JanardhanCommented:
is all the triggers for update action on table2 ?

if so they can be merged as angel suggested
0
 
bmanmike39Author 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?
0
 
SireesCommented:
<<does that mean just put the queries in the order they must happen in the one trigger, one after another?>>

Yes.
0
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.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now