Triggers: Very Good, or Very Bad?
A colleague said this morning "I try to steer clear of triggers"
Part of me immediately thought: "That's stupid! Triggers are powerful and they should be used wherever they're the best tool."
But then a calm inner-voice rose up and reminded me of the dangers of triggers:
"With great power comes great responsibility."
Testing and maintaining a trigger-happy database is comparable to waltzing through a jungle full of trip-wires, booby-traps and landmines.
Hence, as a general rule of thumb we should try to steer clear of triggers.
Before implementing a trigger, ask yourself this much, at least:
- "Is there an alternative technique?" (i.e. a technique that doesn't require a trigger)
- "Is the alternative technique no more than twice* as complex as the trigger technique?"
[* 'twice' may not be the figure you prefer -- determine a suitable factor for your own methods.]
If the answer is "no" to either of those questions then it's Trigger Time baby!
I do love a good trigger!
One little tip: you might want to have some nice strongly-typed methods in your DAL for turning the triggers on and off at will. [Note to self: this is particularly important when working on a HR system with a trigger that sends email notifications for application-level events (such as termination of employees) to board-level executives. Forgetting to disarm such a trigger during testing might cause undue stress to your boss, their boss, their boss's boss, and in turn, to yourself.]Next → ← Previous
I'm currently writing a book about how to build your first product. If you want to build your first product, please sign up to be notified when the book is available.