List all stored procedures with schema name

非 Y 不嫁゛ 提交于 2019-12-03 03:32:34
SELECT [schema] = OBJECT_SCHEMA_NAME([object_id]),
  name
FROM sys.procedures;

or

SELECT [schema] = SCHEMA_NAME([schema_id]),
  name
FROM sys.procedures;

For a specific database, you can just change the context to that database first, or change Marc's query slightly (my queries are no good in this case because they rely on functions that are context-sensitive):

SELECT 
    SchemaName = s.name,
    ProcedureName = pr.name 
FROM 
    databasename.sys.procedures pr
INNER JOIN 
    databasename.sys.schemas s ON pr.schema_id = s.schema_id;

If you want to do this for all databases:

DECLARE @sql NVARCHAR(MAX) = N'';

SELECT @sql += N'
  UNION ALL SELECT db = N''' + name + ''', 
    s.name COLLATE Latin1_General_CI_AI,
    o.name COLLATE Latin1_General_CI_AI
  FROM ' + QUOTENAME(name) + '.sys.procedures AS o
  INNER JOIN ' + QUOTENAME(name) + '.sys.schemas AS s
  ON o.[schema_id] = s.[schema_id]'
FROM sys.databases
-- WHERE ... -- probably don't need system databases at least

SELECT @sql = STUFF(@sql, 1, 18, '') 
  -- you may have to adjust  ^^ 18 due to copy/paste, cr/lf, tabs etc 
  + ' ORDER BY by db, s.name, o.name';

EXEC sp_executesql @sql;

The collate clauses are necessary in case you have databases with different collations.

Try this:

SELECT 
    SchemaName = s.name,
    ProcedureName = pr.name 
FROM 
    sys.procedures pr
INNER JOIN 
    sys.schemas s ON pr.schema_id = s.schema_id

This should list all stored procedures and their schema name as a result set.

Both views - sys.procedures and sys.schemas - have quite a few more attributes - check them out, if you need them, include them in your query.

this may help You..

SELECT * FROM sys.procedures;

You can use Script Generator to get them. In the left pan right click on the database for which you want to get Stored Procedures, Tasks->Generate Scripts Click Next and choose Select Specific Database Objects and select Stored Procedures and click on next, there you can customize as you need and generate the scripts.

Try this:

execute [sys].[sp_stored_procedures]

Or try this and also get all parameters:

execute [sys].[sp_sproc_columns]

Ok...you'll have to loop through all DB catalog names with this, but...

Krushna
SELECT name,crdate  FROM dbo.sysobjects WHERE (type = 'P')  order by name 

SELECT [schema] = OBJECT_SCHEMA_NAME([object_id]),name FROM sys.procedures;

select OBJECT_SCHEMA_NAME([object_id]) as 'SchemaName',name as 'SP Name ' ,

create_date,modify_date FROM sys.procedures order by OBJECT_SCHEMA_NAME([object_id]), name 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!