MySQL - SHOW CREATE PROCEDURE Statement



MySQL SHOW CREATE PROCEDURE Statement

Stored procedures are sub routines, segment of SQL statements which are stored in SQL catalog. All the applications that can access Relational databases (Java, Python, PHP etc.), can access stored procedures.

Stored procedures contain IN and OUT parameters or both. They may return result sets in case you use SELECT statements. Stored procedures can return multiple result sets.

The SHOW CREATE PROCEDURE statement displays the (string) query used to create the specified procedure.

Syntax

Following is the syntax of the SHOW CREATE PROCEDURE statement −

SHOW CREATE PROCEDURE procedureName;

Where, procedure_name is the name of the procedure you need to alter.

Example

Suppose we have created a table named Employee in the database using the CREATE statement as shown below −

CREATE TABLE Employee(
   Name VARCHAR(255), 
   Salary INT, 
   Location VARCHAR(255));

Now, let us insert some records into the Employee table −

INSERT INTO Employee VALUES 
('Amit', 6554, 'Hyderabad'),
('Sumith', 5981, 'Vishakhapatnam'),
('Sudha', 7887, 'Vijayawada');

Assume we have created a stored procedure named myProcedure. Here we are inserting a column in to the Employee table taking values from user. (through input parameters)

DELIMITER //
Create procedure myProcedure (
   IN name VARCHAR(30),
   IN sal INT,
   IN loc VARCHAR(45))
   BEGIN
      INSERT INTO Employee(Name, Salary, Location) VALUES (name, sal, loc);
   END //
DELIMITER ;

Following query displays the CREATE statement used to create the above procedure −

SHOW CREATE PROCEDURE myProcedure\G;

Output

Following is the output of the above query −

************ 1. row ************
       Procedure: myProcedure
        sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
Create Procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE 
                  `myProcedure`(
   IN name VARCHAR(30),
   IN sal INT,
   IN loc VARCHAR(45))
   COMMENT 'This is a sample comment'
   BEGIN
      INSERT INTO Employee(Name, Salary, Location) VALUES 
	  (name, sal, loc);
   END
character_set_client: cp850
collation_connection: cp850_general_ci
  Database Collation: utf8mb4_0900_ai_ci
1 row in set (0.07 sec)
Advertisements