1.   declare   @str   varchar(100)  
  2.   set   @str='PH'     --要搜索的字符串  
  3.    
  4.  declare   @s   varchar(8000)  
  5.   declare   tb   cursor   local   for  
  6.   select   s='if   exists(select   1   from   ['+b.name+']   where   ['+a.name+']   like   ''%'+@str+'%'')  
  7.   print   ''所在的表及字段:   ['+b.name+'].['+a.name+']'''  
  8.   from   syscolumns   a   join   sysobjects   b   on   a.id=b.id  
  9.   where   b.xtype='U'   and   a.status>=0  
  10.      and   a.xusertype   in(175,239,231,167)  
  11.   open   tb  
  12.   fetch   next   from   tb   into   @s  
  13.   while   @@fetch_status=0  
  14.   begin  
  15.   exec(@s)  
  16.   fetch   next   from   tb   into   @s  
  17.   end  
  18.   close   tb  
  19.   deallocate   tb
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐