views:

7081

answers:

10

Is there a query that returns the names of all the stored procedures in an MS SQL database (excluding "System Stored Procedures" would be a nice touch)?

+1  A: 

select *
from dbo.sysobjects where xtype = 'P' and status >0

TrickyNixon
status > 0 doesn't seem to differentiate between system stored procedures and those created
Hmm. It does for us -- I don't know why.
TrickyNixon
+3  A: 

SELECT name, type FROM dbo.sysobjects WHERE (type = 'P')

Kevin
This is deprecated as per [http://msdn.microsoft.com/en-us/library/ms177596.aspx]
btk
+2  A: 

From my understanding the "preferred" method is to use the information_schema tables:

select * from information_schema.routines where routine_type = 'PROCEDURE'

Mike
the returned records don't seem to have a way to differentiate the system stored procedures
+13  A: 

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_')
Dave_H
A: 

sql server 2005 has views that let you grab sprocs, parameters, tables, columns etc.

Its all built in now!

Anonymous Box
+1  A: 

Unfortunately INFORMATION_SCHEMA doesn't contain info about the system procs.

SELECT *
FROM sys.objects
WHERE objectproperty(object_id, N'IsMSShipped') = 0
    AND objectproperty(object_id, N'IsProcedure') = 1
Cade Roux
+1  A: 

If you are using SQL Server 2005 the following will work:

select * from sys.procedures where is_ms_shipped = 0

cbeuker
A: 

i tried the above query in sql server 2005. its giving invalid object name sys.procedures

Are you sure you're connecting to a 2005 *server*, not just using the 2005 *client*?
devstuff
A: 

If you want to do someting to them check this link:

YordanGeorgiev
A: 

Hi

Can u tell me how can i get Store proc execution Time and it executed by whom (log details)

sathiskumar