All Products
Search
Document Center

PolarDB:Triggers

Last Updated:Dec 17, 2024

A trigger is a named Structured Process Language (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 considered fired when the code block is executed.

The event that causes a trigger to fire can be any combination of an insert, update, or delete carried out on the table, either directly or indirectly. If the table is the object of an SQL INSERT, UPDATE, or DELETE statement, the trigger is directly fired assuming that the corresponding insert, update, or delete event is defined as a triggering event. The events that fire the trigger are defined in the CREATE TRIGGER statement.

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 will also be deleted. If deletion is a triggering event on the child table, deletion of the children will cause the trigger to fire.