How to Drop a Stored Procedure in MySQL
In this tutorial, we are going to see how to drop a stored procedure in a MySQL database. In MySQL, a procedure is a stored program in which you can pass parameters. It does not return a value like a function.
Syntax:
DROP PROCEDURE deletes a procedure stored in a database.
Here is the syntax of the statement DROP PROCEDURE:
DROP PROCEDURE [IF EXISTS] my_procedure;
In this syntax:
- First, specify the name of the stored procedure you want to delete after DROP PROCEDURE keyword.
- Secondly, use IF EXISTS option to delete the stored procedure if it exists.
When you delete a procedure that does not exist without using IF EXISTS option, MySQL generates an error. In this case, if you use the IF EXISTS option, MySQL only sends a warning.
Example:
Start by creating a new stored procedure:
DELIMITER $ CREATE PROCEDURE getCustomers() BEGIN SELECT * FROM Customers; END$ DELIMITER ;
Then use DROP PROCEDURE to delete the getCustomers() stored procedure:
DROP PROCEDURE IF EXISTS getCustomers;