SHOW TRIGGERS
The SHOW TRIGGERS statement displays triggers defined for tables in a database.
The syntax of the SHOW TRIGGERS statement is as follows:
SHOW TRIGGERS
[{FROM | IN} database_name]
[LIKE 'pattern' | WHERE expr]
The FROM clause specifies the database. If not specified, the default database is used. The SHOW TRIGGERS statement returns results only for databases and tables with the TRIGGER privilege.
The LIKE clause (if present) specifies the table name (not the trigger name) to match and displays the triggers for these tables. You can use the WHERE clause to specify conditions for selecting rows.
The output of the SHOW TRIGGERS statement includes the following information:
-
Trigger: the trigger name. -
Event: the event that activates the trigger. This is the type of operation associated with the table on which the trigger is activated. The value can beINSERT(a row is inserted),DELETE(a row is deleted), orUPDATE(a row is modified). -
Table: the table for which the trigger is defined. -
Statement: the statement executed when the trigger is activated. -
Timing: whether the trigger is activated before or after the event. The value can beBEFOREorAFTER. -
Created: the date and time the trigger was created. The value is of typeTIMESTAMP(2)(with a fractional part in hundredths of a second). -
sql_mode: the SQL mode in effect when the trigger was created. -
Definer: the user account that created the trigger, in the format'user_name'@'host_name'. -
character_set_client: the value of thecharacter_set_clientsystem variable in the current session when the trigger was created. -
collation_connection: the value of thecollation_connectionsystem variable in the current session when the trigger was created. -
Database Collation: the collation of the database associated with the trigger.
You can also obtain trigger information from the INFORMATION_SCHEMA TRIGGERS table. For more information, see INFORMATION_SCHEMA TRIGGERS.
Here is an example of the SHOW TRIGGERS statement:
SHOW TRIGGERS LIKE 'test_trg%'\G
*************************** 1. row ***************************
Trigger: test_trg
Event: UPDATE
Table: test
Statement: TRIGGER test_trg BEFORE UPDATE ON test
FOR EACH ROW
BEGIN
IF NEW.user_num < 1 THEN
SET NEW.user_num = 1;
ELSEIF NEW.user_num > 45 THEN
SET NEW.user_num= 45;
END IF;
END
Timing: BEFORE
Created: 2022-05-18 18:07:51.994639
sql_mode: STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE
Definer: 'root'@'%'
character_set_client: utf8mb4
collation_connection: utf8mb4
Database Collation: utf8mb4