How to say创建过程,如果在MySQL中不存在
问题描述:
我试图编写一个脚本在MySQL数据库中创建一个过程,但是我想检查它是否首先存在.
I am trying to write a script to create a procedure in MySQL database, but I want to check if it exsit first.
我知道如何对表执行此操作,但是当我对存储过程使用相同的语法时,它不会编译.
I know how to do it for a table, but when I use the same syntax for stored procedure, it doesn't compile.
有人知道吗?谢谢
答
只需删除该过程(如果确实存在),然后重新添加即可:
Just drop the procedure if it does exist and then re-add it:
DROP PROCEDURE IF EXISTS my_procedure;
CREATE PROCEDURE my_procedure()