Action Clause

The Action clause defines the SQL statements that are executed when the trigger is activated. For a trigger on a table, there can be up to three sections in the Action clause: BEFORE, AFTER and FOR EACH ROW.
  • The BEFORE actions are executed once for each triggering event, before the database server performs the triggering DML operation.
  • The AFTER actions are also executed once for each triggering DML event, after the operation on the table is complete, in the context of the triggering statement.
  • The FOR EACH ROW actions are executed for each row that is inserted, updated, deleted or selected in the DML operation, after the DML operation is executed on each row, but before the database server writes the values into the log and into the table.

If the same table has multiple triggers that are activated by the same triggering event, the order of trigger execution is not guaranteed, but all of the BEFORE triggered actions execute before any of the FOR EACH ROW triggered actions, and all of the AFTER triggered actions execute after all of the FOR EACH ROW triggered actions.

When you define an INSTEAD OF trigger on a view, the BEFORE and AFTER keywords are not supported, but the FOR EACH ROW section of the Action clause is valid. See the section INSTEAD OF Triggers on Views for the syntax of specifying triggered actions on a view.

The Action clause has the following syntax.

(1)
Action Clause

1?  BEFORE  %Triggered Action1?  FOR EACH ROW  %Triggered Action1?  AFTER  %Triggered Action1

For the trigger to have any effect on the table, you must define at least one triggered action, using the keywords BEFORE, FOR EACH ROW, or AFTER to indicate when the action occurs relative to execution of the triggering event.

You can specify actions for any or all of these three options on a single trigger, but any BEFORE action list must be specified first, and any AFTER action list must be specified last. For more information on the Action clause when a REFERENCING clause is also specified, see Correlated Table Action.