How do you create triggers in DB2?
The syntax to create a trigger in DB2 is as follows:
CREATE TRIGGER trigger_name
AFTER INSERT ON table_name
REFERENCING NEW AS new
FOR EACH ROW
BEGIN
-- trigger logic here
END;
The above code contains a CREATE TRIGGER statement used to create a trigger with the specified name trigger_name. AFTER INSERT ON table_name specifies that the trigger should be activated after an insertion operation and specifies the table on which the trigger should act. REFERENCING NEW AS new is used to reference the newly inserted row data. FOR EACH ROW specifies that the trigger should operate on each row of data. The logic code for the trigger is contained between BEGIN and END.
You can adjust the trigger timing, action table, and logic code according to your own needs.