Skip to main content

What types of triggers exist?

Trigger types in SQL are split by when they fire and by the type of event they react to.

1. By timing

  1. BEFORE, runs before an INSERT, UPDATE, or DELETE operation changes the data. Used to check or modify values before they're saved. Example: automatically filling in a date if one wasn't given.
  2. AFTER, fires after the data has changed. Often used for logging or updating related tables.
  3. (In some DBMSes) INSTEAD OF, runs in place of the operation. Used, for example, in views, to define custom behavior when data is changed through a VIEW.

2. By event type

  1. INSERT trigger, reacts to new records being added.
  2. UPDATE trigger, fires when data changes.
  3. DELETE trigger, runs when records are deleted.

So a trigger can be described as a combination of both traits, for example:

  • BEFORE INSERT
  • AFTER UPDATE
  • INSTEAD OF DELETE

Each type lets the database automatically control or supplement data operations at the right moment.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.