Home >> FAQs/Tutorials >> SQL Server FAQ
SQL Server FAQ - sys.sql_modules - Getting Stored Procedure Definitions Back
(Continued from previous topic...)
How To Get the Definition of a Stored Procedure Back?
If you want get the definition of an existing stored procedure back from the SQL Server,
you can use the system view called sys.sql_modules, which stores definitions of views
and stored procedures.
The sys.sql_modules holds stored procedure definitions identifiable by the object id of each view.
The tutorial exercise below shows you how to retrieve the definition of stored procedure, "ShowFaq"
by joining sys.sql_modules and sys.procedures:
FROM sys.sql_modules m, sys.procedures p
WHERE m.object_id = p.object_id
AND p.name = 'ShowFaq';
CREATE PROCEDURE ShowFaq AS BEGIN
PRINT 'Number of questions:';
SELECT COUNT(*) FROM Faq;
PRINT 'First 5 questions:'
SELECT TOP 5 * FROM Faq;
CREATE TABLE Faq (Question VARCHAR(80));
(1 row(s) affected)
(Continued on next topic...)
- What Are Stored Procedures?
- How To Create a Simple Stored Procedure?
- How To Execute a Stored Procedure?
- How To List All Stored Procedures in the Current Database?
- How To Drop an Existing Stored Procedure?
- How To Create a Stored Procedure with a Statement Block?
- How To End a Stored Procedure Properly?
- How To Generate CREATE PROCEDURE Script on an Existing Stored Procedure?
- How To Get the Definition of a Stored Procedure Back?
- How To Modify an Existing Stored Procedure?
- How To Create Stored Procedures with Parameters?
- How To Provide Values to Stored Procedure Parameters?
- What Are the Advantages of Passing Name-Value Pairs as Parameters?
- Can You Pass Expressions to Stored Procedure Parameters?
- How To Provide Default Values to Stored Procedure Parameters?
- How To Define Output Parameters in Stored Procedures?
- How To Receive Output Values from Stored Procedures?
- How To Create a Local Temporary Stored Procedure?
- Can Another User Execute Your Local Temporary Stored Procedures?