Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 130039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:53:06+00:00 2026-05-11T05:53:06+00:00

For another question, I’m running into a misconception that seems to arise here at

  • 0

For another question, I’m running into a misconception that seems to arise here at SO occasionally. Some questioners seem to think that Triggers are to Databases as Events are to OOP.

Does anyone have a good analogy to explain why this is a flawed comparison, and the consequences of misapplying it?


EDIT:

Bill K. has hit it correctly, but maybe doesn’t see the importance of the critical differeence between the event and the callback function that strikes me, anyway. Triggers actually cause code to execute every time the event occurs; callbacks only occur whenever one has been registered for an event (which is not true for the vast majority of events); and even then, in most cases the callback’s first action is to deregister itself (or at least the callback contains a qualifcation exit so it only executes once.)

If you write a trigger, it will unfailingly execute every time the event occurs, because there’s no way to register or deregister to code segment.

Triggers are a way to interpose repeating logic synchronously into the thread of execution (i.e. synchronicity). Events are a means to defer logic until later (i.e. implement asynchronicity).

There are exceptions and mitigations in both cases, but the basic patterns of triggers and callbacks are mostly opposite in intention and implementation. Often the distinction doesn’t seem to have fully sunk in. (IMHO, YMMV). 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:53:07+00:00Added an answer on May 11, 2026 at 5:53 am

    They’re not the same thing, but they’re not unrelated.

    In both cases, the mechanism can be described approximately as follows:

    • Some block of code declares ‘interest’ for changes in state.
    • Your application affects some change.
    • The system runs the block of code in response to the change.

    Perhaps a database trigger is more like a callback function that has registered interest in a specific event.

    Here’s an analogy: the event is a rubber ball that you throw. The trigger is a dog that chases after a thrown ball.

    If there’s some other difference that you have in mind that makes it ‘dangerous’ (note: OP has edited this choice of word out of the question) to compare triggers and events, you can describe what you mean.


    Triggers are a way to interpose repeating logic synchronously into the thread of execution (i.e. synchronicity). Events are a means to defer logic until later (i.e. implement asynchronicity).

    Okay, I see what you mean more clearly. But I think it’s in some ways subject to the implementation. I wouldn’t assume an event handler has to deregister itself; it depends on the system you’re using. A UNIX signal handler, for example, has to prevent itself from catching a new signal while it’s already handling one. But a Java servlet inside a Tomcat container should be thread-safe because it may be called concurrently by multiple threads. They’re both event handlers, of different kinds.

    Event handlers may be synchronous or asynchronous. Can a handler in a publish/subscribe system read messages that were posted recently, but prior to the handler registering its interest? Or only messages posted concurrently?


    There’s another important reason to treat triggers as different from event handlers: I frequently recommend against doing anything in a trigger that affects state outside the database.

    For example, sending an email, writing to a file, posting to a web service, or forking a process is inappropriate inside a trigger. If for no other reason than the transaction that spawned the trigger may be rolled back, but you can’t roll back those external effects. You may not even be using explicit transactions, but say you send an email in a BEFORE trigger, but the operation fails because of a NOT NULL constraint or something.

    Instead, all such work should be done by code in one’s application, after one has confirmed that the SQL operation was successful and the transaction committed.

    It’s too bad that people keep trying to do inappropriate work inside a trigger. There are senior developers at MySQL who promote UDFs to read and write data in memcached. Wow — I just noticed these have made it into the MySQL 6.0 product!! Shocking!

    So here’s another attempt at an analogy, comparing triggers and events to the process of a criminal trial:

    • A BEFORE trigger is an allegation.
    • An AFTER trigger is an indictment.
    • COMMIT is a conviction after a guilty verdict.
    • ROLLBACK is an acquittal after an innocent verdict.

    You only want to put the perpetrator in prison after they are convicted.

    • Whereas an EVENT is the crime itself.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 255k
  • Answers 255k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I moved our product, small 7 man team, to Hudson.… May 13, 2026 at 10:25 am
  • Editorial Team
    Editorial Team added an answer That is not exactly how you are supposed to make… May 13, 2026 at 10:25 am
  • Editorial Team
    Editorial Team added an answer another option # convert to Date day_table$day <- as.Date(day_table$day, format="%Y/%m/%d")… May 13, 2026 at 10:25 am

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
For another question, I'm running into a misconception that seems to arise here at
I'm quoting part of an answer which I received for another question of mine
Thanks for your help on my last noobie jquery question and since you done
I'm probably missing something simple here, but I can't find the answer elsewhere. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.