Add triggers

This topic shows how to add triggers to a 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. Start of changeUse one of the following methods to associate the trigger program with a specific database file: End of change

    • Start of changeUse iSeries™ Navigator to create a new file or edit the properties of an existing file.End of change
    • Use the Add Physical File Trigger (ADDPFTRG) command.
    • Use the CREATE TRIGGER SQL statement.
Note: If the trigger program resides in QTEMP library, the trigger program cannot be associated with a physical file.

Start of changeAfter 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.End of change

Start of changeYou 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.End of change

Start of changeYou 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.End of change

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

These required authorities are listed here:
  • Object management or Alter authority to the file
  • Object operational authority to the file
  • Read data rights to the file
  • Update data rights and Object operational authority to the file if CRTPFTRG ALWREPCHG(*YES) is specified
  • Execute authority to the file's library
  • Execute authority to the trigger program
  • Execute authority to the trigger program's library
The file must have appropriate data capabilities before you add a trigger:
  • CRTPF ALWUPD(*NO) conflicts with *UPDATE Trigger
  • CRTPF ALWDLT(*NO) conflicts with *DELETE Trigger
Related reference
Add Physical File Trigger (ADDPFTRG) command