如何获得一个数据库中的所有表和各表中的所有字段的名称。(30分)

  • 主题发起人 主题发起人 mnlisa
  • 开始时间 开始时间
M

mnlisa

Unregistered / Unconfirmed
GUEST, unregistred user!
用ADO连接数据库,什么语句可以获得所有的表和字段?
 
表明成: ADOConnection1.GetTableNames
字段名称:
for i:= 0 to ADOQuery1.FieldCount-1
adoQuery1.Fields.FullName;
....

 
用Session部件,它有一个GetTableNames方法可以取得数据库中的所有的表。
另外Table又一个GetFieldNames可以取得表中所有的字段名。
具体的参数看看help吧!:)
 
同意halps,应该可以搞定
 
获得所有表名
select name from sysobjects where xtype='u'
获得制定表的所有字段
select T1.* from syscolumns t1,sysobject2 t2 where
t1.id=t2.id and t2.name=:tablename
 
同意halps,这是最简单的方法了
 
谢谢大家,我明天试一下,

to book523:
xtype='u'
‘u’代表什么意思?
 
to fanny501:
for i:= 0 to ADOQuery1.FieldCount-1
adoQuery1.Fields.FullName;
这些语句不能得到全部的字段名,只能得到sql语句中的select中选择的那些字段,
而且FieldCount等于select中字段的总数。


 
得到答案了:
表名:
procedure GetTableNames(List: TStrings; SystemTables: Boolean = False);

Description

Call GetTableNames to retrieve a list of tables in the associated database.

List is the already-existing string list object into which the tables names are put.

Set SystemTables to indicate whether the list of table names should include the database抯 system tables.

ADOConnection1.GetTableNames(ListBox2.Items, False);


字段名:
procedure GetFieldNames(const TableName: String; List: TStrings);

其中 可以为:Tdatabase,Tdataset,Tsession,都有这样的方法

 
我的分数实在太少,不好给分,请见凉!!^_^
 
多人接受答案了。
 
后退
顶部