Keywords: Triggers, example of trigger actions

# Examples of trigger actions

The following trigger action copies a row from the flights table into the flight_history table whenever any row gets inserted into flights and adds the comment "inserted from trig1" in the status column of the flight_history table.

    CREATE TRIGGER trig1
    AFTER UPDATE ON flights
    REFERENCING OLD AS UPDATEDROW
    FOR EACH ROW MODE DB2SQL
    INSERT INTO flights_history
    VALUES (UPDATEDROW.FLIGHT_ID, UPDATEDROW.SEGMENT_NUMBER,
    UPDATEDROW.ORIG_AIRPORT, UPDATEDROW.DEPART_TIME,
    UPDATED ROW.DEST_AIRPORT, UPDATEDROW.ARRIVE_TIME,
    UPDATEDROW.MEAL, UPDATEDROW.FLYING_TIME, UPDATEDROW.MILES,
    UPDATEDROW.AIRCRAFT,'INSERTED FROM trig1');

Parent topic: Programming trigger actions
Related concepts
Trigger action overview
Performing referential actions
Accessing before and after rows
Triggers and exceptions