1.0

Table Of Contents
Note: Only row triggers can use transition variables. INSERT row triggers cannot reference an OLD row,
and DELETE row triggers cannot reference a NEW row.
The ReferencingClause can designate only one new correlation or identier and only one old correlation or
identier.
A row trigger res once for each row affected by the triggering event. If no rows are affected, the trigger does
not re.
triggered-sql-statement
The action dened by the trigger is called the triggered-sql-statement. This statement has the following limitations:
It must not contain any dynamic parameters (?).
It must not create, alter, or drop the table upon which the trigger is dened.
It must not add an index to or remove an index from the table on which the trigger is dened.
It must not add a trigger to or drop a trigger from the table upon which the trigger is dened.
It must not commit or roll back the current transaction or change the isolation level.
Before triggers cannot have INSERT, UPDATE or DELETE statements as their action.
Before triggers cannot call procedures that modify SQL data as their action.
The triggered-sql-statement can reference database objects other than the table where the trigger is declared. If
any of these database objects is dropped, the trigger is invalidated. If the trigger cannot be recompiled on the
next execution, the invocation throws an exception and the statement that caused the trigger to re is rolled back.
Example
This trigger is an after trigger on created dom.ights. For every UPDATE event made on
dom.ights, the trigger inserts a row in dom.ights_history:
CREATE TRIGGER trig1
AFTER UPDATE ON dom.flights REFERENCING OLD AS UPDATEDROW
FOR EACH ROW MODE DB2SQL
INSERT INTO dom.flights_history
VALUES(UPDATEDROW.FLIGHT_ID, UPDATEDROW.AIRCRAFT, 'INSERTED
FROM trig1');
The following trigger res after a DELETE event:
CREATE TRIGGER trig2
AFTER DELETE ON flights
REFERENCING OLD AS OLD
FOR EACH ROW
DELETE FROM flightavailability WHERE FLIGHT_ID =
OLD.FLIGHT_ID;
To avoid recursive calls to a trigger, you can use a table column as a ag to stop triggering
further events. For example:
CREATE TRIGGER trig3
AFTER UPDATE OF the_flag ON test_table
REFERENCING NEW AS updatedRow
FOR EACH ROW
UPDATE test_table SET edited_by = 'fromUpdateTrigger',
edited_date = CURRENT_DATE WHERE the_data=updatedRow.the_data
vFabric SQLFire User's Guide466
vFabric SQLFire Reference