7.13. Triggers

A trigger is a database object associated to a table or a view that contains some application logic, which is executed automatically upon an INSERT, UPDATE, or DELETE operation on the table or view. For example, you can use a trigger:

  • To validate the input in an INSERT statement

  • To compare the new value of a row being updated to an old value

  • To insert logging information to another table for audit trail purposes when a row is deleted

Triggers can be classified as BEFORE, AFTER, or INSTEAD OF triggers.

BEFORE triggers are activated before any table data is affected by the triggering SQL statement. For example, if you are inserting a row into a table, the BEFORE trigger is activated first, before the INSERT is completed.

AFTER triggers ...

Get Understanding DB2®: Learning Visually with Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.