About Triggers

From InterBase
Jump to: navigation, search

Go Up to Triggers (Data Definition Guide)


A trigger is a self-contained routine associated with a table or view that automatically performs an action when a row in the table or view is inserted, updated, or deleted.

A trigger is never called directly. Instead, when an application or user attempts to INSERT, UPDATE, or DELETE a row in a table, any triggers associated with that table and operation are automatically executed, or fired.

Triggers can make use of exceptions, named messages called for error handling. When an exception is raised by a trigger, it returns an error message, terminates the trigger, and undoes any changes made by the trigger, unless the exception is handled with a WHEN statement in the trigger.

The advantages of using triggers are:

  • Automatic enforcement of data restrictions, to make sure users enter only valid values into columns.
  • Reduced application maintenance, since changes to a trigger are automatically reflected in all applications that use the associated table without the need to recompile and re-link.
  • Automatic logging of changes to tables. An application can keep a running log of changes with a trigger that fires whenever a table is modified.
  • Automatic notification of changes to the database with event alerters in triggers.

Topics