要删除触发器,请使用DROP命令。语法如下-
DROP TRIGGER IF EXISTS yourTriggerName;
要了解上述语法,您需要在当前数据库中有一个触发器。
要检查触发器是否存在,可以使用以下查询。我们在数据库中有一个触发器-
mysql> show triggers;
以下是输出-
+-------------+--------+---------------+------------------------------------------------------------------------+--------+------------------------+--------------------------------------------+---------+----------------------+----------------------+--------------------+ | Trigger | Event | Table | Statement | Timing |Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation | +-------------+--------+---------------+------------------------------------------------------------------------+--------+------------------------+--------------------------------------------+---------+----------------------+----------------------+--------------------+ | CheckSalary | INSERT | employeetable | if new.EmployeeSalary < 1000 then setnew.EmployeeSalary = 10000;end if | BEFORE | 2018-12-31 17:33:29.54 |STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | root@% | utf8 |utf8_general_ci | utf8mb4_0900_ai_ci | +-------------+--------+---------------+------------------------------------------------------------------------+--------+------------------------+--------------------------------------------+---------+----------------------+----------------------+--------------------+ 1 row in set (0.17 sec)
在这里,我们在employeetable上使用名称为“ CheckSalary”的触发器。使用DROP命令删除触发器“ CheckSalary”。查询如下-
mysql> drop trigger if exists CheckSalary;
使用show triggers命令检查触发器是否存在。查询如下-
mysql> show triggers; Empty set (0.00 sec)
现在看上面的结果,触发器不存在数据库“ test”。我们使用drop删除了它。