A trigger provides a mechanism for executing a series of SQL statements when a particular action (an INSERT, UPDATE, or DELETE) occurs. The body of the trigger contains the SQL statement(s) that the user wants to execute. The body of the trigger is written using the stored procedure language (see CREATE PROCEDURE).
You can create one or more triggers on a table, with each trigger defined to activate on a specific INSERT, UPDATE, or DELETE command. When a user modifies data within the table, the trigger that corresponds to the command is activated.
You can only use inline SQL or stored procedures with triggers. If you use a stored procedure in the trigger, the procedure must be created with the CREATE PROCEDURE command. A procedure invoked from a trigger body can invoke other triggers.
To create a trigger, you must be a DBA or owner of the table on which the trigger is being defined.
Triggers are created with the CREATE TRIGGER statement and dropped from the system catalog with the DROP TRIGGER statement. Triggers can also be disabled with the ALTER TRIGGER statement.
Example
"CREATE TRIGGER TRIGGER_BI ON TRIGGER_TEST BEFORE INSERT REFERENCING NEW BI AS NEW_BI BEGIN EXEC SQL PREPARE BI INSERT INTO TRIGGER_OUTPUT VALUES ( ’BI’, TRIG_NAME(0), TRIG_SCHEMA(0)); EXEC SQL EXECUTE BI; SET NEW_BI = ’TRIGGER_BI’; END";