A trigger is a named SPL code block that is associated with a table and stored in the database. When a specified event occurs on the associated 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, DELETE, or
TRUNCATE command the trigger is directly fired assuming that the corresponding insert, update, delete, or truncate 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.