declare @str varchar(100)
--设置要模糊搜索的字符串set @str='test004'declare @s varchar(8000)
declare tb cursorlocalforselect s='if exists(select 1 from ['+b.name+'] where ['+a.name+'] like ''%'+@str+'%'') print ''所在的表及字段: ['+b.name+'].['+a.name+']'''from syscolumns a join sysobjects b on a.id=b.id
where b.xtype='U'and a.status>=0and a.xusertype in(175,239,231,167)
open tb
fetchnextfrom tb into @s
while @@fetch_status=0beginexec(@s)
fetchnextfrom tb into @s
endclose tb
deallocate TB