在数据库内快速查找字符串

方法一,是我自己经常用到的:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
select a.name,b.text from sys.sysobjects a inner join syscomments b
on a.id = b.id and b.text like '%你要找的字符串%'

 

方法二:

刚在外文资料上看到的:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
--Declare whatever you can :)
Declare @SString nvarchar(50)
Declare @getdbname sysname
Declare @sqlstm nvarchar(1000)
Declare dbname cursor for 

--get all the names of the Databases in order by name
Select '['+name+']' from master.dbo.sysdatabases order by name 
open dbname

--Get the first Name
FETCH NEXT FROM dbname into @getdbname

WHILE @@FETCH_STATUS=0
BEGIN

--set the search string
SET @SString = '<Place the String Here>'

--append the search pattern
SET @SString = '%' + @SString + '%'

--set the statement to define the search condition, with variables
SET @sqlstm = '
Select Specific_Catalog as Database_Name, Routine_Name as 
''Stored Procedure Name'',Routine_Definition 
From 
'+ @getdbname+'.Information_Schema.Routines 
Where PatIndex(
'+''''+@SString+''''+', Routine_Definition) > 0'

--Execute the Query
EXEC (@sqlstm)
FETCH NEXT FROM dbname into @getdbname
END

--Close the Cursor and Deallocate it from memory
Close dbname
Deallocate dbname 

 

 

(出处:http://www.sqlservercentral.com/scripts/Search/63397/

 

第二个用的cursor查找,所有库的,二者范围不一样。

供大家急需时参考。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值