How to create a trigger

You use the CREATE TRIGGER statement to define a new trigger. The CREATE TRIGGER statement is a data-definition statement that associates SQL statements, called the triggered action, with a precipitating event on a table. When the event occurs, it triggers the associated SQL statements, which are stored in the database.

In this example, the triggering event is an UPDATE statement that references the quantity column of the items table. The following figure illustrates the relationship of the DML operation that activates the trigger, called the trigger event, to the triggered action.
Figure 1: Trigger event and triggered action

This figure is described in the surrounding text.
The CREATE TRIGGER statement consists of clauses that perform the following actions:
  • Declare a name for the trigger .
  • Specify the DML operation on a specified table or view as the triggering event.
  • Define the SQL operations that this event triggers.

An optional clause, called the REFERENCING clause, is discussed in ids_sqt_531.html#ids_sqt_531.

To create a trigger, use DB-Access or one of the SQL APIs. This section describes the CREATE TRIGGER statement as you enter it with the interactive Query-language option in DB-Access. In an SQL API, you precede the statement with the symbol or keywords that identify it as an embedded statement.