Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving a filtered list of stored procedures using t-sql

I'm trying to get a list of stored procedures in t-sql. I am using the line:

exec sys.sp_stored_procedures;

I would like to filter the results back though, so I only get user created stored procedures. I would like to filter out sp_*, dt_*, fn_*, xp_* and everything else that is a system stored procedure and no interest to me. How can I manipulate the result set returned?

Using Sql Server 2008 express.

Solved! Here is what I used:

SELECT name FROM sys.procedures
WHERE [type] = 'P'
AND name NOT LIKE 'sp_%'
AND name NOT LIKE 'dt_%'
ORDER BY name ASC;
like image 242
DanDan Avatar asked Mar 26 '10 10:03

DanDan


People also ask

How do I view the content of a stored procedure in SQL Server?

Expand Databases, expand the database in which the procedure belongs, and then expand Programmability. 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.


3 Answers

Rather than using the Stored Procedure you can use the following views:

Select * From sys.procedures
Where [Type] = 'P'

or

Select * From Information_Schema.Routines
like image 164
codingbadger Avatar answered Sep 28 '22 08:09

codingbadger


Select items from the sysobjects table and use a where clause type = 'P' for stored procedures and filter on name.

like image 35
Dave Anderson Avatar answered Sep 28 '22 09:09

Dave Anderson


SELECT [Routine_Name]
FROM   [INFORMATION_SCHEMA].[ROUTINES]
WHERE  [ROUTINE_TYPE] = 'PROCEDURE'
like image 43
Howard Rothenburg Avatar answered Sep 28 '22 10:09

Howard Rothenburg