A trigger is an SPL code block
that is given a name, associated with a table, and stored in the
database. When certain events occur on the table
the SPL code block is executed.
The trigger is said to be fired when the
code block is executed.
The event that causes a trigger to fire can be any combination
of an insert, update, or deletion carried out on the table,
either directly or indirectly. If the table is the object of
a SQL INSERT,
UPDATE, or DELETE command
the trigger is directly fired assuming that the corresponding
insert, update, or deletion event is defined as a
triggering event. The events that fire
the trigger are defined in the CREATE TRIGGER
command.
A trigger can be fired indirectly if a triggering event occurs on
the table as a result of an event initiated on another table.
For example, if a trigger is defined on a table containing a
foreign key defined with the ON DELETE CASCADE
clause and a row in the parent table is deleted, all children
of the parent would be deleted as well. If deletion is a
triggering event on the child table, deletion of the children
will cause the trigger to fire.