12.5 Defining a trigger

By defining a trigger, an SQL statement can be executed automatically in response to some operation on a table (updating, insertion, deletion). A trigger specification involves a table, an SQL statement that serves as the event to activate the trigger (the trigger event), an automatically executed SQL statement (trigger event SQL), and the conditions under which the trigger is activated (the trigger action search conditions). When an SQL statement that matches the trigger action search conditions is executed on a table for which a trigger has been defined, the triggered SQL statement executes automatically. The following figure provides an overview of triggers.

Figure 12-17 Overview of triggers

[Figure]

Explanation:
When the UAP executes a trigger event SQL statement, triggers defined for Table A are called. If trigger action search conditions are satisfied, triggered SQL statements are executed automatically (in this case, a row is inserted into Table B and a row is updated in Table C).
Prerequisite:
Before you define a trigger, you need to create an RDAREA for the data dictionary LOB. Use the database structure modification utility (pdmod) to create the RDAREA for the data dictionary LOB.

When a trigger is defined for a table, all existing functions, procedures, and trigger SQL objects that the table uses become invalid and have to be re-created. The trigger SQL object will also become invalid and will have to be re-created if any of the resources used by the trigger (such as tables or indexes) are defined, modified, or deleted. For details, see 12.5.4 Trigger management.

Organization of this section
12.5.1 Application standards
12.5.2 Defining a trigger
12.5.3 Trigger considerations
12.5.4 Trigger management
12.5.5 Error recovery