A trigger is a named database object that is associated with a table
and that is activated when a particular event occurs for the table.
For example, the following statements create a table and an
INSERT trigger. The trigger sums the values
inserted into one of the table's columns:
CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));
Query OK, 0 rows affected (0.03 sec)
CREATE TRIGGER ins_sum BEFORE INSERT ON account
FOR EACH ROW SET @sum = @sum + NEW.amount;
Query OK, 0 rows affected (0.06 sec)
This chapter describes the syntax for creating and dropping
triggers, and shows some examples of how to use them. Discussion of
restrictions on use of triggers is given in
Section I.1, “Restrictions on Stored Routines and Triggers”. Remarks regarding binary
logging as it applies to triggers are given in
Section 19.4, “Binary Logging of Stored Routines and Triggers”.