MySQL

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;
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *