日期:2014-05-20  浏览次数:20805 次

求教一个数据库中查询表内容的问题
现壮:       在一个数据库中有很多个表(table),   我只知道在其中一个表中有什么样的内容.
问题:       我想通过我所了解的内容,   查询这些内容在哪一个表中

  请教有什么方法可以达到这个目的的呢?

------解决方案--------------------
那你先转换成xml,借助xml的技术,比较容易实现你的要求。。。
------解决方案--------------------
知不知道这个内容有那些字段中呢,如果知道就方便构造成动态sql找出来
------解决方案--------------------
如果知道字段的名称
可以在系统表里得到表的名称
具体哪个系统表记不得了
------解决方案--------------------
那你都知道哪些信息啊...

根据知道信息量的多少具体确定解决方案..
------解决方案--------------------
系统表

sysobjects 记录:表名,主键,外键关系,...
syscolumns 记录: 列(其中colid与sysobjects.uid关联,id与sysobjects.id关联)

貌似这些就足够完成你所需要的了
------解决方案--------------------
将数据库中的表分别读到DataSet中一个个进行分析吧..

好像没啥好办法..


------解决方案--------------------
select distinct tb.name as 表名,col.name as 列名,tp.name as 类型, col.length as 长度
from sysobjects as tb,syscolumns as col,systypes as tp
where tb.id = col.id and tb.xtype = 'U ' and col.xtype = tp.xtype
order by tb.name,col.name
------------------------------------------------
你自己改改吧。
------解决方案--------------------
借飞翔兄的例子 也就是
select distinct tb.name as 表名,col.name as 列名,tp.name as 类型, col.length as 长度
from sysobjects as tb,syscolumns as col,systypes as tp
where tb.id = col.id and tb.xtype = 'U ' and col.xtype = tp.xtype
order by tb.name,col.name
通过col.name来查找表的
搂主可以试试
------解决方案--------------------
还真不好解决.期待
------解决方案--------------------
create proc tableName(@value varchar(100) )--你要查询的数据
as
declare @table_name
declare @col_name
create table #temp
(
table_name varchar(100),
col_name varchar(100)
)
insert into #temp(table_name,col_name)
select distinct tb.name as 表名,col.name as 列名
from sysobjects as tb,syscolumns as col,systypes as tp
where tb.id = col.id and tb.xtype = 'U ' and col.xtype = tp.xtype
order by tb.name,col.name
declare @cursor_table cursor
set @cursor_table = distinct table_name from #temp
open @cursor_table
fetch next from @cursor_table into @table_name
while (@@fetch_status=0)
begin
declare @cursor_col cursor
set @cursor_col =col_name from #temp where table_name=@table_name
open @cursor_col
fetch next from @cursor_col into @col_name
while (@@fetch_status=0)
begin
if(exist(select * from @table_name where @col_name=@value))--这里的用变量做表怎么写的呢?我忘了
begin
close @cursor_col
deallocate @cursor_col
close @cursor_table
deallocate @cursor_table
drop table #temp
select @table_name
return
fetch next from @cursor_col into @col_name
end
fetch next from @cursor_table into @table_name
end
end