A trigger is a schema object that defines a set of actions (SQL statements) that are to be executed when a specific SQL data change operation occurs on a specified table.
triggeris a schema object that defines a set of actions (SQL statements) that are to be executed when a specific SQL data change operation occurs on a specified table. Triggers provide automatic execution of a set of SQL statements whenever a specified event occurs. These SQL statements can validate and edit database changes, read and modify the database, and invoke functions that perform operations both inside and outside the database. You can use triggers with referential constraints and check constraints to enforce data integrity rules.
Triggers provide several improvements to the development and execution of DB2 applications:
- Faster application development. Because triggers are stored in the database, the actions performed by triggers do not have to be coded in each application.
- Code reusability. A trigger can be defined once and then used by any application that accesses the table on which it is defined.
- Easier maintenance. If a business policy changes, only a change to the corresponding triggers is needed, instead of changes to each application program.
You can create, alter, template, and drop triggers. If more than one trigger is selected on the alter or template panels, the selections are processed in the order that the triggers are displayed. Each selected trigger is processed one at a time. Confirm the first selected trigger to start this process. When batch processing is complete, the next trigger is displayed.
Creating a trigger defines a trigger in a schema and builds a trigger package at the current server. Using the template option, you can create a trigger by using an existing trigger as a template. When entering and managing the trigger text, you can use any of the standard ISPF editor commands to copy, replicate, delete, and move lines within the trigger's text. Use the HEADER command to provide a larger work area for managing your trigger's text. The command acts like a toggle to show and remove the header.
When working with triggers, the COMPARE command is useful when you are templating or altering a trigger. It shows the old and new versions of the trigger. Use the RESET command to reset the attributes.
According to Db2 rules, a trigger can be dropped by a privilege set that is defined below and must include at least one of the following:
- Ownership of the trigger.
- The DROPIN privilege for the schema or all schemas. The authorization ID that matches the schema name implicitly has the DROPIN privilege on the schema
- SYSADM or SYSCTRL authority.