The SQL for a triggered action can start with a WHEN clause that specifies the condition under which the action is to occur.
If you want the action to occur before a trigger event, the code must include one of the following statements:
If you want the action to occur after a trigger event, the code must include one of the following statements:
Example: A trigger called REORDER ensures that whenever a parts record is updated, the following check and (if necessary) action is taken:
If the on-hand quantity is less than 10% of the maximum stocked quantity, then issue a shipping request ordering the number of items for the affected part to be equal to the maximum stocked quantity minus the on-hand quantity.
In the following definition of REORDER:
CREATE TRIGGER reorder AFTER UPDATE OF on_hand, max_stocked ON parts REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL WHEN (n.on_hand < 0.10 * n.max_stocked) BEGIN ATOMIC VALUES(issue_ship_request(n.max_stocked - n.on_hand, n.partno)); END
For more examples of SQL for triggered actions, see online help for correlation names and temporary tables. See also "CREATE TRIGGER" in the SQL Reference.
[ Top of Page | Table of Contents | Glossary | Index ]