日期:2014-05-19  浏览次数:20481 次

SQL数据检索
条件:
    1:我有一个数据库:AAA  

    2:知道数据AAA中有个表或则多个表包含下面的信息;

        BBBBBB
结论:
        我想知道数据库:AAA中有哪些表的某哪个字段包含有信息:BBBBBB

------解决方案--------------------
declare @str varchar(100)
set @str= 'White ' --要搜索的字符串

declare @s varchar(8000)
declare tb cursor local for
select 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> =0
and a.xusertype in(175,239,231,167)
open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb