To view the list of the stored procedure, you can query the information_schema. routines table. It contains the list of the stored procedure and stored functions created on the database. To view the list of the stored procedure created in a sakila database, run the following query.
As Mike stated, the best way is to use information_schema
. As long as you're not in the master database, system stored procedures won't be returned.
SELECT *
FROM DatabaseName.INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = 'PROCEDURE'
If for some reason you had non-system stored procedures in the master database, you could use the query (this will filter out MOST system stored procedures):
SELECT *
FROM [master].INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = 'PROCEDURE'
AND LEFT(ROUTINE_NAME, 3) NOT IN ('sp_', 'xp_', 'ms_')
SELECT name,
type
FROM dbo.sysobjects
WHERE (type = 'P')
From my understanding the "preferred" method is to use the information_schema tables:
select *
from information_schema.routines
where routine_type = 'PROCEDURE'
The following will Return All Procedures in selected database
SELECT * FROM sys.procedures
You can try this query to get stored procedures and functions:
SELECT name, type
FROM dbo.sysobjects
WHERE type IN (
'P', -- stored procedures
'FN', -- scalar functions
'IF', -- inline table-valued functions
'TF' -- table-valued functions
)
ORDER BY type, name
You can use one of the below queries to find the list of Stored Procedures in one database :
Query1 :
SELECT
*
FROM sys.procedures;
Query2 :
SELECT
*
FROM information_schema.routines
WHERE ROUTINE_TYPE = 'PROCEDURE'
If you want to find the list of all SPs in all Databases you can use the below query :
CREATE TABLE #ListOfSPs
(
DBName varchar(100),
[OBJECT_ID] INT,
SPName varchar(100)
)
EXEC sp_msforeachdb 'USE [?]; INSERT INTO #ListOfSPs Select ''?'', Object_Id, Name FROM sys.procedures'
SELECT
*
FROM #ListOfSPs
If you are using SQL Server 2005 the following will work:
select *
from sys.procedures
where is_ms_shipped = 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With