The following queries will return a list of all Stored Procedures in the database, with basic information about each Stored Procedure:
SELECT *
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = 'PROCEDURE'
The ROUTINE_NAME
, ROUTINE_SCHEMA
and ROUTINE_DEFINITION
columns are generally the most useful.
SELECT *
FROM sys.objects
WHERE type = 'P'
SELECT *
FROM sys.procedures
Note that this version has an advantage over selecting from sys.objects since it includes the additional columns is_auto_executed
, is_execution_replicated
, is_repl_serializable
, and skips_repl_constraints
.
SELECT *
FROM sysobjects
WHERE type = 'P'
Note that the output contains many columns that will never relate to a stored procedure.
The next set of queries will return all Stored Procedures in the database that include the string 'SearchTerm':
SELECT o.name
FROM syscomments c
INNER JOIN sysobjects o
ON c.id=o.id
WHERE o.xtype = 'P'
AND c.TEXT LIKE '%SearchTerm%'
SELECT p.name
FROM sys.sql_modules AS m
INNER JOIN sys.procedures AS p
ON m.object_id = p.object_id
WHERE definition LIKE '%SearchTerm%'