A trigger is a type of stored procedure program that is automatically called whenever a specified action is performed on a specific table. Unlike other stored procedures, they are application independent and cannot be circumvented. You can specify a trigger program to be called before or after a change operation occurs. The change operation can be an insert, update, or delete operation. You can add a maximum of 300 triggers to a table.
Triggers are useful for keeping audit trails, for detecting exceptional conditions, for maintaining relationships in the database, and for running applications and operations that coincide with the change operation.
You can create two types of triggers:
System trigger:
A system trigger may be written in Control Language (CL), Structured Query Language (SQL), or any high-level language with the exception of Java.SQL trigger:
An SQL trigger is written using SQL syntax.
Note: On pre-V5R1 systems, you can only add system triggers. Also, you can only add 6 triggers to a table, one for each change operation and time.
In addition, you can create an INSTEAD OF SQL trigger to updatable views. INSTEAD OF triggers are processed instead of the insert, update, or delete statement that activates the trigger. INSTEAD OF triggers can only be defined on views and certain other logical files. For example, you cannot add an INSTEAD OF trigger to an index.
You can do the following tasks with triggers:
For more information, see SQL trigger or
External trigger in the
i5/OS Information Center.