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."

(more on trigger-thinking...)

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:

  1. "Is there an alternative technique?" (i.e. a technique that doesn't require a trigger)
  2. "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.]


My book "Choose Your First Product" is available now.

It gives you 4 easy steps to find and validate a humble product idea.

Learn more.

(By the way, I read every comment and often respond.)

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.