什么查询可以返回SQL Server数据库中所有存储过程的名称
如果查询可以排除系统存储过程,那将更有帮助。
什么查询可以返回SQL Server数据库中所有存储过程的名称
如果查询可以排除系统存储过程,那将更有帮助。
当前回答
根据我的理解,“首选”方法是使用information_schema表:
select *
from information_schema.routines
where routine_type = 'PROCEDURE'
其他回答
我编写了这个简单的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
获取对象的最佳方法是使用sys.sql_modules。您可以从这个表中找到所需的所有内容,并通过object_id将这个表与其他表连接起来以获取更多信息
SELECT o. object_id,o.name AS name,o.type_desc,m.definition,schemas.name scheamaName
FROM sys.sql_modules m
INNER JOIN sys.objects o ON m.object_id=o.OBJECT_ID
INNER JOIN sys.schemas ON schemas.schema_id = o.schema_id
WHERE [TYPE]='p'
SELECT name,
type
FROM dbo.sysobjects
WHERE (type = 'P')
根据我的理解,“首选”方法是使用information_schema表:
select *
from information_schema.routines
where routine_type = 'PROCEDURE'