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
- BEFORE, runs before an
INSERT,UPDATE, orDELETEoperation changes the data. Used to check or modify values before they're saved. Example: automatically filling in a date if one wasn't given. - AFTER, fires after the data has changed. Often used for logging or updating related tables.
- (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
- INSERT trigger, reacts to new records being added.
- UPDATE trigger, fires when data changes.
- DELETE trigger, runs when records are deleted.
So a trigger can be described as a combination of both traits, for example:
BEFORE INSERTAFTER UPDATEINSTEAD OF DELETE
Each type lets the database automatically control or supplement data operations at the right moment.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.