触发器
The TRIGGERS
table provides information about triggers. To see information about a table's triggers, you must have the TRIGGER
privilege for the table.
INFORMATION_SCHEMA Name | SHOW Name | Remarks |
---|---|---|
TRIGGER_CATALOG | def | |
TRIGGER_SCHEMA | ||
TRIGGER_NAME | Trigger | |
EVENT_MANIPULATION | Event | |
EVENT_OBJECT_CATALOG | def | |
EVENT_OBJECT_SCHEMA | ||
EVENT_OBJECT_TABLE | Table | |
ACTION_ORDER | ||
ACTION_CONDITION | NULL | |
ACTION_STATEMENT | Statement | |
ACTION_ORIENTATION | ROW | |
ACTION_TIMING | Timing | |
ACTION_REFERENCE_OLD_TABLE | NULL | |
ACTION_REFERENCE_NEW_TABLE | NULL | |
ACTION_REFERENCE_OLD_ROW | OLD | |
ACTION_REFERENCE_NEW_ROW | NEW | |
CREATED | Created | |
SQL_MODE | sql_mode | MySQL extension |
DEFINER | Definer | MySQL extension |
CHARACTER_SET_CLIENT | character_set_client | MySQL extension |
COLLATION_CONNECTION | collation_connection | MySQL extension |
DATABASE_COLLATION | Database Collation | MySQL extension |
Notes:
-
The names in the “
SHOW
Name” column refer to theSHOW TRIGGERS
statement, notSHOW CREATE TRIGGER
. See Section 13.7.5.38, “SHOW TRIGGERS Syntax”. -
TRIGGER_SCHEMA
andTRIGGER_NAME
: The name of the database in which the trigger occurs and the trigger name, respectively. -
EVENT_MANIPULATION
: The trigger event. This is the type of operation on the associated table for which the trigger activates. The value is'INSERT'
(a row was inserted),'DELETE'
(a row was deleted), or'UPDATE'
(a row was modified). -
EVENT_OBJECT_SCHEMA
andEVENT_OBJECT_TABLE
: As noted in Section 23.3, “Using Triggers”, every trigger is associated with exactly one table. These columns indicate the database in which this table occurs, and the table name, respectively. -
ACTION_ORDER
: The ordinal position of the trigger's action within the list of triggers on the same table with the sameEVENT_MANIPULATION
andACTION_TIMING
values. Before MySQL 5.7.2, this value is always0
because it is not possible for a table to have more than one trigger with the sameEVENT_MANIPULATION
andACTION_TIMING
values. -
ACTION_STATEMENT
: The trigger body; that is, the statement executed when the trigger activates. This text uses UTF-8 encoding. -
ACTION_ORIENTATION
: Always contains the value'ROW'
. -
ACTION_TIMING
: Whether the trigger activates before or after the triggering event. The value is'BEFORE'
or'AFTER'
. -
ACTION_REFERENCE_OLD_ROW
andACTION_REFERENCE_NEW_ROW
: The old and new column identifiers, respectively. This means thatACTION_REFERENCE_OLD_ROW
always contains the value'OLD'
andACTION_REFERENCE_NEW_ROW
always contains the value'NEW'
. -
CREATED
: The date and time when the trigger was created. This is aTIMESTAMP(2)
value (with a fractional part in hundredths of seconds) for triggers created in MySQL 5.7.2 or later,NULL
for triggers created prior to 5.7.2. -
SQL_MODE
: The SQL mode in effect when the trigger was created, and under which the trigger executes. For the permitted values, see Section 5.1.8, “Server SQL Modes”. -
DEFINER
: The account of the user who created the trigger, in'
format.user_name
'@'host_name
' -
CHARACTER_SET_CLIENT
: The session value of thecharacter_set_client
system variable when the trigger was created. -
COLLATION_CONNECTION
: The session value of thecollation_connection
system variable when the trigger was created. -
DATABASE_COLLATION
: The collation of the database with which the trigger is associated. -
The following columns currently always contain
NULL
:ACTION_CONDITION
,ACTION_REFERENCE_OLD_TABLE
, andACTION_REFERENCE_NEW_TABLE
.
Example, using the ins_sum
trigger defined in Section 23.3, “Using Triggers”:
mysql> SELECT * FROM INFORMATION_SCHEMA.TRIGGERS
WHERE TRIGGER_SCHEMA='test' AND TRIGGER_NAME='ins_sum'\G
*************************** 1. row ***************************
TRIGGER_CATALOG: def
TRIGGER_SCHEMA: test
TRIGGER_NAME: ins_sum
EVENT_MANIPULATION: INSERT
EVENT_OBJECT_CATALOG: def
EVENT_OBJECT_SCHEMA: test
EVENT_OBJECT_TABLE: account
ACTION_ORDER: 1
ACTION_CONDITION: NULL
ACTION_STATEMENT: SET @sum = @sum + NEW.amount
ACTION_ORIENTATION: ROW
ACTION_TIMING: BEFORE
ACTION_REFERENCE_OLD_TABLE: NULL
ACTION_REFERENCE_NEW_TABLE: NULL
ACTION_REFERENCE_OLD_ROW: OLD
ACTION_REFERENCE_NEW_ROW: NEW
CREATED: 2013-07-05 07:41:21.26
SQL_MODE: NO_ENGINE_SUBSTITUTION
DEFINER: me@localhost
CHARACTER_SET_CLIENT: utf8
COLLATION_CONNECTION: utf8_general_ci
DATABASE_COLLATION: latin1_swedish_ci