如果 MySQL 中存在,则删除触发器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18370380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:36:16 来源:igfitidea点击:
Drop trigger if exists in MySQL
提问by richardtk_1
I need to execute a command similar to the following not inside a procedure but inside a simple sql file for mysql 5.xx
我需要在 mysql 5.xx 的简单 sql 文件中而不是在过程中执行类似于以下内容的命令
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'tr_fnninio_censopersona_ins') THEN
DROP TRIGGER tr_fnninio_censopersona_ins;
END IF;
回答by juergen d
Why not just
为什么不只是
DROP TRIGGER IF EXISTS tr_fnninio_censopersona_ins;
回答by caras
You can use like this,
你可以这样使用,
DROP TRIGGER IF EXISTS tr_fnninio_censopersona_ins;
DELIMITER $$
CREATE TRIGGER tr_fnninio_censopersona_ins
BEFORE INSERT ON `your_table` FOR EACH ROW
BEGIN
SET NEW.INSERTED= NOW();
END$$
DELIMITER ;