Chapter 14. Triggers

Table of Contents
14.1. Overview
14.2. Types of Triggers
14.3. CREATE TRIGGER
14.4. Trigger Variables
14.5. Transactions and Exceptions
14.6. Trigger Examples
14.6.1. Before Statement-Level Trigger
14.6.2. After Statement-Level Trigger
14.6.3. Before Row-Level Trigger
14.6.4. After Row-Level Trigger

This chapter describes triggers in EnterpriseDB. As with procedures and functions, triggers are written in the EDB-SPL language.

14.1. Overview

A trigger is an EDB-SPL code block that is given a name, associated with a table, and stored in the database. When certain events occur on the table the EDB-SPL code block is executed. The trigger is said to be fired when the code block is executed.

The event that causes a trigger to fire can be any combination of an insert, update, or deletion carried out on the table, either directly or indirectly. If the table is the object of a SQL INSERT, UPDATE, or DELETE command the trigger is directly fired assuming that the corresponding insert, update, or deletion event is defined as a triggering event. The events that fire the trigger are defined in the CREATE TRIGGER command.

A trigger can be fired indirectly if a triggering event occurs on the table as a result of an event initiated on another table. For example, if a trigger is defined on a table containing a foreign key defined with the ON DELETE CASCADE clause and a row in the parent table is deleted, all children of the parent would be deleted as well. If deletion is a triggering event on the child table, deletion of the children will cause the trigger to fire.