查詢sql2005用户数据库所有表中的一个值

declare @str varchar(100)
set @str='系统'
declare @s varchar(max)
declare c_tb cursor local for --申明游标
  select b='if exists(select 1 from  ['+b.name+'] where ['+a.name+'] like ''%'+@str+'%'')  
  print  ''select ['+a.name+'] from ['+b.name+']'''  
  from   syscolumns   a   join   sysobjects   b   on   a.id=b.id  
  where   b.xtype='U'   and   a.status>=0  
     and   a.xusertype   in(175,239,231,167) 
open c_tb
fetch next from c_tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from c_tb into @s
end
close c_tb
deallocate c_tb
原文地址:https://www.cnblogs.com/Luouy/p/1964905.html