Table of Contents [+/-]
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:
mysql>CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));Query OK, 0 rows affected (0.03 sec) mysql>CREATE TRIGGER ins_sum BEFORE INSERT ON account->FOR EACH ROW SET @sum = @sum + NEW.amount;Query OK, 0 rows affected (0.06 sec)
MySQL triggers are activated by SQL statements
only. They are not activated by changes in
tables made by APIs that do not transmit SQL statements to the
MySQL Server; in particular, they are not activated by updates
made using the NDB API.
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 D.1, “Restrictions on Stored Routines, Triggers, and Events”. Remarks regarding binary logging as it applies to triggers are given in Section 22.4, “Binary Logging of Stored Routines and Triggers”.
For answers to some common questions about triggers in MySQL 5.1, see Section A.5, “MySQL 5.1 FAQ — Triggers”.

User Comments
A DROP DATABASE on a database with triggers fails, so you must drop triggers before droping database.
A DROP TRIGGER fails if the table doesn't exists, so drop tiggers before.
Add your own comment.