INSERT Events and DELETE Events
Element | Description | Restrictions | Syntax |
---|---|---|---|
table | Name of the triggering table | Must exist in the database | Identifier |
An Insert trigger is activated when an INSERT statement includes the specified table (or a synonym for table) in its INTO clause. Similarly, a Delete trigger is activated when a DELETE statement includes the specified table (or a synonym for table) in its FROM clause.
The MERGE statement can also activate an Insert trigger, if the specified table of the Insert trigger is the target table of a MERGE statement that includes the Insert clause. Similarly, the MERGE statement can also activate a Delete trigger, if the specified table of the Delete trigger is the target table of a MERGE statement that includes the Delete clause.
The TRUNCATE TABLE statement does not activate Delete triggers when it removes all the rows from a table. If an enabled Delete trigger is defined for a table on which you do not hold the Alter privilege, the database server returns an error if you attempt to truncate that table, even though the TRUNCATE statement cannot be the triggering event for a Delete trigger. (For more information about the discretionary access privileges that truncate operations require, see the TRUNCATE statement.)
For triggers on views, the INSTEAD OF keywords must immediately precede the INSERT, DELETE, or UPDATE keyword that specifies the type of trigger event, and the name or synonym of a view (rather than of a table) must follow the ON keyword. The section INSTEAD OF Triggers on Views describes the syntax for defining INSTEAD OF trigger events.
Any number of Insert triggers, and any number of Delete triggers, can be defined on the same table.
If you define a trigger on a subtable within a table hierarchy, and the subtable supports cascading deletes, then a DELETE operation on the supertable activates the Delete triggers on the subtable.
See also the section Re-Entrancy of Triggers for information about dependencies and restrictions on the actions of Insert triggers and Delete triggers.