Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View stored procedure/function definition in MySQL

What is the MySQL command to view the definition of a stored procedure or function, similar to sp_helptext in Microsoft SQL Server?

I know that SHOW PROCEDURE STATUS will display the list of the procedures available. I need to see a single procedure's definition.

like image 757
Srinivas M.V. Avatar asked Dec 28 '09 10:12

Srinivas M.V.


People also ask

How do you view the definition of a stored procedure?

Expand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To. Select New Query Editor Window. This will display the procedure definition.

How do I view functions in MySQL?

Showing stored functions using MySQL WorkbenchStep 1. Connect to the database that you want to show the stored functions. Step 2. Open the Functions menu, you will see a list of functions which belong to the database.

What is stored procedure and function in MySQL?

Stored routines (procedures and functions) are supported in MySQL 5.0. A stored procedure is a set of SQL statements that can be stored in the server. Once this has been done, clients don't need to keep reissuing the individual statements but can refer to the stored procedure instead.

What is view and stored procedure in SQL?

A SQL View is a virtual table, which is based on SQL SELECT query. A view references one or more existing database tables or other views. It is the snap shot of the database whereas a stored procedure is a group of Transact-SQL statements compiled into a single execution plan.


2 Answers

SHOW CREATE PROCEDURE <name> 

Returns the text of a previously defined stored procedure that was created using the CREATE PROCEDURE statement. Swap PROCEDURE for FUNCTION for a stored function.

like image 186
afftee Avatar answered Sep 30 '22 19:09

afftee


You can use this:

SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'yourdb' AND ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_NAME = "procedurename"; 
like image 27
Haim Evgi Avatar answered Sep 30 '22 19:09

Haim Evgi