To view stored procedure/function definition in MySQL, you can use show command. The syntax is as follows −
SHOW CREATE PROCEDURE yourProcedureName;
To understand the above syntax, you can create a procedure and check that definition. Let us create a stored procedure −
mysql> delimiter // mysql> create procedure AllRecords() -> begin -> select *from student; -> end // Query OK, 0 rows affected (0.24 sec)
You can call the stored procedure with the help of call command. The query is as follows −
mysql> delimiter ; mysql> call AllRecords();
The following is the output −
+------+-------+ | id | Name | +------+-------+ | 1 | John | | 2 | Bob | | 3 | Smith | | 6 | John | +------+-------+ 4 rows in set (0.14 sec) Query OK, 0 rows affected (0.18 sec)
Now you can check the definition with the help of above syntax which we discussed in the beginning. The query is as follows −
mysql> show create procedure AllRecords;
Here is the output −
+------------+--------------------------------------------+-----------------------------------------------------------------------+----------------------+----------------------+--------------------+ | Procedure | sql_mode | Create Procedure | character_set_client | collation_connection | Database Collation | +------------+--------------------------------------------+-----------------------------------------------------------------------+----------------------+----------------------+--------------------+ | AllRecords | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | CREATE DEFINER=`root`@`%` PROCEDURE `AllRecords`() begin select *from student;end | utf8 | utf8_general_ci | utf8mb4_unicode_ci | +------------+--------------------------------------------+-----------------------------------------------------------------------+----------------------+----------------------+--------------------+ 1 row in set (0.00 sec)
To check the function definition in MySQL, you can use function in place of procedure. The syntax is as follows: −
SHOW CREATE FUNCTION yourFunctionName;