SQL搜索字符串对应的表和字段

来源:互联网 发布:eviews软件下载 编辑:程序博客网 时间:2024/05/17 00:18
  1. --SQL搜索字符串对应的表和字段
  2. declare @str varchar(100)
  3. set @str='关键字'  --要搜索的字符串
  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
原创粉丝点击