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

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


当前回答

我编写了这个简单的tsql来列出所有存储过程的文本。请确保在字段中替换数据库名称。

use << database name >>
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' order by p.name;
open allSP;
fetch next from allSP into @spName;
while (@@FETCH_STATUS = 0)
begin
    set @aQuery = 'sp_helptext [Extract.' + @spName + ']';
    exec sp_executesql @aQuery;
    fetch next from allSP;
end;
close allSP;
deallocate allSP;

其他回答

如果你使用的是SQL Server 2005,下面的操作可以正常工作:

select *
  from sys.procedures
 where is_ms_shipped = 0

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

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

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


GO 

这将在mssql上工作。

select * from DatabaseName.INFORMATION_SCHEMA.ROUTINES where routine_type = 'PROCEDURE'

select * from DatabaseName.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')
select *  
  from dbo.sysobjects
 where xtype = 'P'
   and status > 0