什么查询可以返回SQL Server数据库中所有存储过程的名称

如果查询可以排除系统存储过程,那将更有帮助。


当前回答

这将返回所有sp名称

Select * 
FROM sys.procedures where [type] = 'P' 
     AND is_ms_shipped = 0 
     AND [name] not like 'sp[_]%diagram%'

其他回答

这也可以帮助列出除了系统过程之外的过程:

select * from sys.all_objects where type='p' and is_ms_shipped=0

我调整了上面LostCajun的优秀帖子,排除了系统存储过程。我还从代码中删除了“Extract.”,因为我不知道它是干什么用的,它给了我错误。循环中的“fetch next”语句还需要一个“into”子句。

use <<databasename>>
go

declare @aQuery nvarchar(1024);
declare @spName nvarchar(64);
declare allSP cursor for
    select p.name  
    from sys.procedures p 
    where p.type_desc = 'SQL_STORED_PROCEDURE' 
    and LEFT(p.name,3) NOT IN ('sp_','xp_','ms_')
    order by p.name;
open allSP;
fetch next from allSP into @spName;
while (@@FETCH_STATUS = 0)
begin
    set @aQuery = 'sp_helptext [' + @spName + ']';
    exec sp_executesql @aQuery;
    fetch next from allSP into @spName;
end;
close allSP;
deallocate allSP;

只是名字:

SELECT SPECIFIC_NAME  
FROM YOUR_DB_NAME.information_schema.routines  
WHERE routine_type = 'PROCEDURE'

这个,列出所有你想要的东西

在Sql Server 2005, 2008, 2012:

Use [YourDataBase]

EXEC sp_tables @table_type = "'PROCEDURE'" 
EXEC sp_tables @table_type = "'TABLE'"
EXEC sp_tables @table_type = "'VIEW'" 

OR

SELECT * FROM information_schema.tables
SELECT * FROM information_schema.VIEWS

下面将返回所选数据库中的所有过程

SELECT * FROM sys.procedures