什么查询可以返回SQL Server数据库中所有存储过程的名称
如果查询可以排除系统存储过程,那将更有帮助。
什么查询可以返回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;
其他回答
select *
from dbo.sysobjects
where xtype = 'P'
and status > 0
SELECT name,
type
FROM dbo.sysobjects
WHERE (type = 'P')
你可以尝试这个查询来获取存储过程和函数:
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
这将返回所有sp名称
Select *
FROM sys.procedures where [type] = 'P'
AND is_ms_shipped = 0
AND [name] not like 'sp[_]%diagram%'
根据我的理解,“首选”方法是使用information_schema表:
select *
from information_schema.routines
where routine_type = 'PROCEDURE'