Adding triggers

 

You can add a trigger to a specific database file.

To add a trigger, follow these steps:

  1. Ensure that you have the proper authority and the file has the proper data capabilities.

  2. Use one of the following methods to associate the trigger program with a specific database file:

If the trigger program resides in QTEMP library, the trigger program cannot be associated with a physical file.

After you have created the association between the trigger program and the file, the system calls the trigger program when a change or read operation is initiated against the database file, a member of the file, and any logical file created over the physical file.

You can associate a maximum of 300 triggers with one database file. Each insert, delete, or update operation can call multiple triggers before and after the operation occurs. Each read operation can call multiple triggers after the operation occurs. This topic shows how to add a trigger to a file.

You can associate a maximum of three triggers with one logical file. That is, you can create one INSTEAD OF trigger per insert, update, or delete operation. The trigger is called instead of performing the operation.

The number of triggers called after a read operation that is issued by a query might not be equal to the number of records that are actually returned. This is because the query might have read a different number of records, causing a trigger to be called for each read operation, before returning the correct number of records.

An SQL update operation involves a simultaneous read operation followed by a write operation. Read triggers are not run for SQL update operations. An update trigger should be specified to cover this read operation followed by a write operation.

 

Required authorities and data capabilities for triggers

To add triggers, have the following required authorities:

The file must have appropriate data capabilities before you add a trigger:

 

Parent topic:

Triggering automatic events in your database