Create, Delete, and Alter a Stored Procedure

This lesson covers the basics on creating, viewing, altering and removing a stored procedure.

Create, Alter, and Delete a Stored Procedure

To create a stored procedure we use the CREATE PROCEDURE statement. CREATE PROCEDURE keywords are followed by the procedure name. We can also specify parameters to our procedure as a comma separated list withing parenthesis after the procedure name. The body of the stored procedure is enclosed with in the BEGIN and END keywords.

In order to delete a stored procedure, the ALTER ROUTINE privilege is a must. The DROP PROCEDURE statement deletes a stored procedure from the database. It can be used with the optional IF EXISTS clause.

Syntax

DELIMITER **

CREATE PROCEDURE procedure_name( parameter_list )

BEGIN

procedure_body

END**

DELIMITER ;

DROP PROCEDURE [IF EXISTS] procedure_name;

Connect to the terminal below by clicking in the widget. Once connected, the command line prompt will show up. Enter or copy-paste the command ./DataJek/Lessons/51lesson.sh and wait for the mysql prompt to start-up.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.