sqlserver如何查询所有数据库中包含某段字符串的存储过程名,结果展示为数据库名字-存储过程名

我知道查询所有数据库名称的sql为
SELECT name FROM master..sysdatabases

查询当前数据库的sql为
select name
from sysobjects o, syscomments s
where o.id = s.id
and text like '%text%'

求大神帮忙。

select name
from sysobjects o, syscomments s
where o.id = s.id
and text like '%querytext%'
and o.xtype = 'P' ORDER BY name

将querytext替换成你想查找的字符串即可。

declare @i as varchar(max)
select @i=isnull(@i,'')+'select name collate database_default from '+name+'.dbo.sysobjects where xtype = ''P'' and name like ''%rep%'' union ' From master.dbo.sysdatabases
set @i=replace(@i+',',' union ,','')
exec (@i)

like ''%rep%'' :
%Z%替换你想查找的字符。