IBM Books

Image, Audio, and Video Extenders Administration and Programming

Triggers

A trigger defines a set of actions that are activated by a change to a table. Triggers can be used to perform actions such as validating input data, automatically generating a value for a newly inserted row, reading from other tables for cross-referencing purposes, or writing to other tables for auditing purposes. Triggers are often used for integrity checking or to enforce business rules.

You create a trigger using an SQL CREATE TRIGGER statement. The following statement creates a trigger to enforce a business rule regarding parts inventory. The trigger reorders a part when the number on hand is less than ten percent of the maximum number stocked.

CREATE TRIGGER reorder
       AFTER UPDATE OF on_hand, max_stocked ON parts
       REFERENCING NEW AS n_row
       FOR EACH ROW MODE DB2SQL
 
       WHEN (n_row.on_hand < 0.10 * n_row.max_stocked)
       BEGIN ATOMIC
              VALUES(issue_ship_request(n_row.max_stocked -
                                   n_row.on_hand,
                                   n_row.partno));
       END

The DB2 extenders create and maintain administrative support tables to record information about image, audio, and video data stored in a database. (See Administrative support tables for more information about these tables.) The extenders use triggers to update these tables when image, audio, or video data is inserted into, updated in, or deleted from a database.


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