2 Day Developer > Using Triggers > Overview of Triggers > When Is a Trigger Fired?
When Is a Trigger Fired? |
Previous |
Next |
A trigger is fired based on a triggering statement, which specifies:
The SQL statement or the system event, database event, or DDL event that fires the trigger body. The options include DELETE
, INSERT
, and UPDATE
. One, two, or all three of these options can be included in the triggering statement specification.
The table, view, database, or schema associated with the trigger.
If a trigger contained the following statement:
AFTER DELETE OR INSERT OR UPDATE ON employees ...
then any of the following statements would fire the trigger:
DELETE FROM employees WHERE ...;
INSERT INTO employees VALUES ( ... );
INSERT INTO employees SELECT ... FROM ... ;
UPDATE employees SET ... ;
An UPDATE
statement might include a list of columns. If a triggering statement includes a column list, the trigger is fired only when one of the specified columns is updated. If a triggering statement omits a column list, the trigger is fired when any column of the associated table is updated. A column list cannot be specified for INSERT
or DELETE
triggering statements. In Example: Creating a Database Trigger WIth the AFTER Option the audit_sal
trigger specifies the salary
column, and is only fired after an UPDATE
of the salary of an employee in the employees
table. Updates of other columns would not fire the trigger.