Spec-Zone .ru
спецификации, руководства, описания, API
|
A trigger is a named database object that is associated with a table, and that activates when a particular event occurs for the table. Some uses for triggers are to perform checks of values to be inserted into a table or to perform calculations on values involved in an update.
A trigger is defined to activate when an INSERT
, DELETE
,
or UPDATE
statement executes for the associated table. A trigger can be set to
activate either before or after the triggering statement. For example, you can have a trigger activate before
each row that is inserted into a table or after each row that is updated.
MySQL triggers are activated by SQL statements only. They are not activated by changes in views, nor by changes to tables made by APIs that do not transmit SQL statements to the MySQL Server. This means that:
Triggers are not activated by changes in INFORMATION_SCHEMA
tables, because these tables are actually views.
Triggers are not activated by updates made using the NDB
API.
The following sections describe the syntax for creating and dropping triggers, and show some examples of how to use them.
You may find the
For answers to some commonly asked questions regarding triggers in MySQL, see Section B.5, "MySQL 5.6 FAQ: Triggers".
There are some restrictions on the use of triggers; see Section E.1, "Restrictions on Stored Programs".
Binary logging for triggers takes place as described in Section 19.7, "Binary Logging of Stored Programs".