SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How many triggers can be implemented in a single table


How many triggers can be implemented in a single table

Author
Message
gopalchettri
gopalchettri
SSC Rookie
SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

Group: General Forum Members
Points: 34 Visits: 116
1. Well the question is simple. How many triggers can be implemented in a single table.

2. If a table has 5 Insert triggers, which trigger will execute first.

Ian Scarlett
Ian Scarlett
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5218 Visits: 7136
1. Well the question is simple. How many triggers can be implemented in a single table.

Effectively unlimited, although you can only have 1 INSTEAD OF INSERT, 1 INSTEAD OF UPDATE and 1 INSTEAD OF DELETE trigger

2. If a table has 5 Insert triggers, which trigger will execute first.

You can use the stored procedure sp_settriggerorder to define the trigger that fires FIRST and/or LAST... the rest will fire in an undefined sequence.

If you are looking to have that many triggers, and the sequence is important, I would seriously consider combining them into a single trigger.

The "triggers are evil" brigade will probably suggest you move the logic elsewhere, and do away with the triggers entirely.



Garadin
Garadin
SSCertifiable
SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)

Group: General Forum Members
Points: 6899 Visits: 4107
TRIGGERS ARE EVIL!










But yeah, I agree with Ian, consolidate triggers wherever possible. Although you can set the trigger order, any time you modify/insert/delete a trigger, that order gets changed and you have to set it again. (At least it does in 2000, not sure if that is different in 2005).

Seth Phelabaum
Consistency is only a virtue if you're not a screwup. ;-)

Links: How to Post Sample Data :: Running Totals :: Tally Table :: Cross Tabs/Pivots :: String Concatenation
GSquared
GSquared
SSC Guru
SSC Guru (56K reputation)SSC Guru (56K reputation)SSC Guru (56K reputation)SSC Guru (56K reputation)SSC Guru (56K reputation)SSC Guru (56K reputation)SSC Guru (56K reputation)SSC Guru (56K reputation)

Group: General Forum Members
Points: 56945 Visits: 9730
If the sequence matters, put it in the trigger code, and don't count on firing sequence.

Most of the time, it's better to have the code in the insert proc instead of a trigger. Not always true, but true more often than not.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Marcin Gol
Marcin Gol
SSC Eights!
SSC Eights! (906 reputation)SSC Eights! (906 reputation)SSC Eights! (906 reputation)SSC Eights! (906 reputation)SSC Eights! (906 reputation)SSC Eights! (906 reputation)SSC Eights! (906 reputation)SSC Eights! (906 reputation)

Group: General Forum Members
Points: 906 Visits: 178
triggers are bad - because ... they are really hard to managed in big database
Ian Scarlett
Ian Scarlett
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5218 Visits: 7136
Marcin Gol [SQL Server MVP] (10/1/2009)
triggers are bad - because ... they are really hard to managed in big database


What makes them harder to manage in a large database, as opposed to a smaller one?



Silverfox
Silverfox
SSCertifiable
SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)

Group: General Forum Members
Points: 6356 Visits: 1161
Ian Scarlett (10/2/2009)
Marcin Gol [SQL Server MVP] (10/1/2009)
triggers are bad - because ... they are really hard to managed in big database


What makes them harder to manage in a large database, as opposed to a smaller one?


Yeah, I dont understand that either, the principle is the same. reardless of size. If triggers are written correctly, you should have no problems.

--------------------------------------------------------------------------------------
Recommended Articles on How to help us help you and
solve commonly asked questions

Forum Etiquette: How to post data/code on a forum to get the best help by Jeff Moden
Managing Transaction Logs by Gail Shaw
How to post Performance problems by Gail Shaw
Help, my database is corrupt. Now what? by Gail Shaw
Aaron Cool
Aaron Cool
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 61
I see triggers as a mixed bag. I use them but only when I think they are the most elegant way of handling a problem. I think that the
triggers are bad - because ... they are really hard to managed in big database
comment was probably referring to the fact that if you are not used to looking for them/using them, they can be forgotten and you can easily have logic occurring that seems to be outside what someone would look for. In a small database where you can be intimately familiar with all the tables it's easier to remember that they are there and operating. In a database with hundreds of tables and only a hand full of triggers, well... Things can be forgotten easier. Just a guess as to what the poster was thinking though.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)

Group: General Forum Members
Points: 221283 Visits: 46280
Please note: 4 year old thread.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search