Triggers

A trigger is a set of actions that are executed automatically whenever a specified event occurs to a specified base table. A trigger can be defined to be executed before the event or after the event. The event can be an insert, update, or delete operation.

The set of actions can include almost any operation allowed on the AS/400 system. A few operations are not allowed, such as:

For a complete list of restrictions, see the Database Programming book.

Because the database manager automatically executes a trigger, if a set of actions must occur whenever a specified operation occurs, applications do not have to duplicate the actions in every application program that performs the operation. This can result in better programmer productivity, better consistency, and in the case of distributed applications, better performance.

The actions performed in the trigger are considered to be part of the operation that caused the trigger to be executed. Thus, when the isolation level is anything other than NC (No Commit) and the trigger actions are performed using the same commitment definition as the trigger event:

A trigger has an attribute that specifies whether it is allowed to delete or update a row that has already been inserted or updated within the SQL statement that caused the trigger to be executed.

A trigger may perform operations that cause other triggers to be fired. Also, operations performed in a trigger may cause referential constraint rules to be executed.

A trigger is not allowed on a table that contains a LOB column.

Triggers are defined using the ADDPFTRG (Add Physical File Trigger) CL command. Triggers are dropped using the RMVPFTRG (Remove Physical File Trigger) CL command. For more information, see the Database Programming book.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]