如何查看数据库中所有触发器的列表?
借助于 SHOW TRIGGERS 语句,我们可以列出特定数据库中的所有触发器。它可以用以下示例进行说明 −
示例
mysql> Show Triggers\G *************************** 1. row *************************** Trigger: trigger_before_delete_sample Event: DELETE Table: sample Statement: BEGIN SET @count = if (@count IS NULL, 1, (@count+1)); INSERT INTO sample_rowaffected values (@count); END Timing: BEFORE Created: 2017-11-21 12:31:58.70 sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERR OR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION Definer: root@localhost character_set_client: cp850 collation_connection: cp850_general_ci Database Collation: latin1_swedish_ci *************************** 2. row *************************** Trigger: before_inser_studentage Event: INSERT Table: student_age Statement: IF NEW.age < 0 THEN SET NEW.age = 0; END IF Timing: BEFORE Created: 2017-11-21 11:26:15.34 sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERR OR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION Definer: root@localhost character_set_client: cp850 collation_connection: cp850_general_ci Database Collation: latin1_swedish_ci 2 rows in set (0.01 sec)
以上结果集给出了当前数据库中的触发器列表。现在,如果我们想要获取特定数据库中触发器的列表,那么我们可以使用以下语句 −
mysql> Show Triggers from tutorials\G Empty set (0.00 sec)
以上结果集显示在名为“tutorials”的数据库中没有触发器。
广告