将如下内容执行在master库里,即可在所有库里执行,按关键字对存储过程内容进行搜索,

名字sp_findproc前的sp_好像必需,否则在其他数据库中执行,会提示找不到。

在所有存储过程中查找关键字CREATE    PROCEDURE [dbo].[sp_findproc] (@akey varchar(255)) AS
在所有存储过程中查找关键字
在所有存储过程中查找关键字
-- 在所有存储过程中查找关键字,关键字不区分大小写
在所有存储过程中查找关键字
declare @aname as varchar(700)
在所有存储过程中查找关键字
declare @atext as varchar(8000)
在所有存储过程中查找关键字
declare @acolid as int
在所有存储过程中查找关键字
declare @pos as int 
在所有存储过程中查找关键字
declare @start as int
在所有存储过程中查找关键字
declare @end as int
在所有存储过程中查找关键字
declare @shorttext as varchar(255)
在所有存储过程中查找关键字
create table #temp_proctext (oid int IDENTITY (11),name varchar(700),text varchar(255),pos int)
在所有存储过程中查找关键字
declare proctext_cursor cursor local  for
在所有存储过程中查找关键字
select  A.name ,B.text,B.colid from sysobjects A,syscomments B  where A.id=B.id and A.type='P' 
在所有存储过程中查找关键字
and  B.text like '%'+@akey+'%' order by A.Name,B.colid
在所有存储过程中查找关键字
open proctext_cursor
在所有存储过程中查找关键字
FETCH NEXT FROM proctext_cursor INTO @aname@atext@acolid
在所有存储过程中查找关键字
while (@@FETCH_STATUS = 0
在所有存储过程中查找关键字
begin
在所有存储过程中查找关键字 
set @pos = charindex(@akey,@atext,1)
在所有存储过程中查找关键字 
while(@pos >0)
在所有存储过程中查找关键字 
begin 
在所有存储过程中查找关键字       
set @start = @pos - 10
在所有存储过程中查找关键字       
if @start <=0 
在所有存储过程中查找关键字          
set @start =1
在所有存储过程中查找关键字       
set @end = @pos + len(@akey+20
在所有存储过程中查找关键字       
if @end > len(@atext
在所有存储过程中查找关键字          
set @end = len(@atext
在所有存储过程中查找关键字       
set @shorttext = Substring(@atext,@start,@end - @start)
在所有存储过程中查找关键字       
insert into #temp_proctext values(@aname,@shorttext,(@acolid-1)*4000+@pos)       
在所有存储过程中查找关键字       
set @pos = charindex(@akey,@atext,@end)   
在所有存储过程中查找关键字 
end
在所有存储过程中查找关键字 
FETCH NEXT FROM proctext_cursor INTO @aname@atext@acolid
在所有存储过程中查找关键字
end
在所有存储过程中查找关键字
CLOSE proctext_cursor
在所有存储过程中查找关键字
DEALLOCATE proctext_cursor
在所有存储过程中查找关键字
select name,pos,text from #temp_proctext order by oid
在所有存储过程中查找关键字
drop table #temp_proctext
在所有存储过程中查找关键字
在所有存储过程中查找关键字
在所有存储过程中查找关键字
GO
在所有存储过程中查找关键字
在所有存储过程中查找关键字

相关文章: