線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1733
推到 Plurk!
推到 Facebook!

如何列出資料庫完整的結構

答題得分者是:timhuang
bestlong
站務副站長


發表:126
回覆:734
積分:512
註冊:2002-10-19

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-10-15 17:26:20 IP:211.22.xxx.xxx 未訂閱
想用程式列出資料庫的結構, 目前用 TADOConnection.GetTables 取得所有的 Table 名稱清單, 然後再用 TADOTable 去開啟每一個 Table, 再用 Fields[i].FieldName 一一列出欄位名稱, 不過要取得結構就要先 Open Table 結果因資料表的記錄很多嚴重影響到速度, 改用 Query 來處理. 不過現在想要列出 Index 方面的資料, 用 indexFields 就都沒有列出, 這部份就不知道該如何處理? 我是雪龍
------
http://blog.bestlong.idv.tw/
http://www.bestlong.idv.tw/
http://delphi-ktop.bestlong.idv.tw/
timhuang
尊榮會員


發表:78
回覆:1815
積分:1608
註冊:2002-07-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-10-15 18:04:24 IP:203.95.xxx.xxx 未訂閱
列出 field name 可以用 TADOConnection 的: procedure GetFieldNames(const TableName: String; List: TStrings); 關於 index 的列舉. 你可以先說明你要查的資料庫種類嗎?
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-10-15 18:07:30 IP:202.39.xxx.xxx 未訂閱
可使用 TADOConnection.OpenSchema 的方式.    --- 歡迎光臨 KTop 研究院
bestlong
站務副站長


發表:126
回覆:734
積分:512
註冊:2002-10-19

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-10-15 23:20:56 IP:211.76.xxx.xxx 未訂閱
引言: 列出 field name 可以用 TADOConnection 的: procedure GetFieldNames(const TableName: String; List: TStrings); 關於 index 的列舉. 你可以先說明你要查的資料庫種類嗎?
目前是要先針對 MS-SQL 6.5 與 MS-SQL 2000 兩個資料庫種類 我是雪龍
------
http://blog.bestlong.idv.tw/
http://www.bestlong.idv.tw/
http://delphi-ktop.bestlong.idv.tw/
bestlong
站務副站長


發表:126
回覆:734
積分:512
註冊:2002-10-19

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-10-15 23:31:33 IP:211.76.xxx.xxx 未訂閱
引言: 可使用 TADOConnection.OpenSchema 的方式. --- 歡迎光臨 KTop 研究院 < face="Verdana, Arial, Helvetica"> procedure OpenSchema(const Schema: TSchemaInfo; const Restrictions: OleVariant; const SchemaID: OleVariant; DataSet: TADODataSet); 今天有看到這個 Methods 項目, 不過一時之間還搞不清楚怎麼運用. 我是雪龍
------
http://blog.bestlong.idv.tw/
http://www.bestlong.idv.tw/
http://delphi-ktop.bestlong.idv.tw/
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-10-16 08:22:28 IP:202.39.xxx.xxx 未訂閱
參考: http://www.geocities.com/technotes2002/ADOMD1.htm
procedure TForm1.Button1Click(Sender: TObject);
var
 SI: TSchemaInfo;
 i: integer;
begin
  //Select a type of metadata query
  case ComboBox1.ItemIndex of
    0: SI := siCubes;
    1: SI := siDimensions;
    2: SI := siHierarchies;
    3: SI := siLevels;
    4: SI := siMeasures;
    5: SI := siProperties;
    6: SI := siMembers;
  end;      //Retrieve results of the metadata query to ADODataSet1
  ADOConnection1.OpenSchema(SI, EmptyParam, EmptyParam, ADODataSet1);
  //Open a query result
  ADODataSet1.Open;
  //Change appearance of the DBGrid
  for i:=0 to DBGrid1.Columns.Count-1 do
    DBGrid1.Columns[i].Width := 80;
end;    procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.ItemIndex := 0;
end;
--- 歡迎光臨 KTop 研究院
bestlong
站務副站長


發表:126
回覆:734
積分:512
註冊:2002-10-19

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-11-11 08:30:21 IP:211.22.xxx.xxx 未訂閱
這幾天翻了一遍手邊的 Delphi 書籍, 赫然發現在 李維先生所著的 [實戰Delphi 5.x ADO/MTS/COM 專業程式設計篇] 一書中就有程式說明與範例. 我是雪龍
------
http://blog.bestlong.idv.tw/
http://www.bestlong.idv.tw/
http://delphi-ktop.bestlong.idv.tw/
Rain
資深會員


發表:31
回覆:236
積分:268
註冊:2003-02-17

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-11-11 10:07:02 IP:220.160.xxx.xxx 未訂閱
書裏邊怎麼做? 下面也是一種方法:取得完整的資料庫結構 執行SQL語句,例如 'select cast(COLUMN_NAME as varchar(20)) 欄位名稱,' 'cast(DATA_TYPE as varchar(10)) 欄位類型,' 'cast(CHARACTER_MAXIMUM_LENGTH as varchar(6)) 長度,' 'cast(COLUMN_DEFAULT as varchar(10)) 預設值,IS_NULLABLE 允許空值 ' 'from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = ''YourTableName'''; 更多,依照下面的說明加進去 TABLE_CATALOG nvarchar(128) Table qualifier. TABLE_SCHEMA nvarchar(128) Table owner. TABLE_NAME nvarchar(128) Table name. COLUMN_NAME nvarchar(128) Column name. ORDINAL_POSITION smallint Column identification number. COLUMN_DEFAULT nvarchar(4000) Default value of the column. IS_NULLABLE varchar(3) Nullability of the column. If this column allows NULL, this column returns YES. Otherwise, NO is returned. DATA_TYPE nvarchar(128) System-supplied data type. CHARACTER_MAXIMUM_LENGTH smallint Maximum length, in characters, for binary data, character data, or text and image data. Otherwise, NULL is returned. For more information, see Data Types. CHARACTER_OCTET_LENGTH smallint Maximum length, in bytes, for binary data, character data, or text and image data. Otherwise, NULL is returned. NUMERIC_PRECISION tinyint Precision of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned. NUMERIC_PRECISION_RADIX smallint Precision radix of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned. NUMERIC_SCALE tinyint Scale of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned. DATETIME_PRECISION smallint Subtype code for datetime and SQL-92 interval data types. For other data types, NULL is returned. CHARACTER_SET_CATALOG varchar(6) Returns master, indicating the database in which the character set is located, if the column is character data or text data type. Otherwise, NULL is returned. CHARACTER_SET_SCHEMA varchar(3) Returns DBO, indicating the owner name of the character set, if the column is character data or text data type. Otherwise, NULL is returned. CHARACTER_SET_NAME nvarchar(128) Returns the unique name for the character set if this column is character data or text data type. Otherwise, NULL is returned. COLLATION_CATALOG varchar(6) Returns master, indicating the database in which the sort order is defined, if the column is character data or text data type. Otherwise, this column is NULL. COLLATION_SCHEMA varchar(3) Returns DBO, indicating the owner of the sort order for character data or text data type. Otherwise, NULL is returned. COLLATION_NAME nvarchar(128) Returns the unique name for the sort order if the column is character data or text data type. Otherwise, NULL is returned. DOMAIN_CATALOG nvarchar(128) If the column is a user-defined data type, this column is the database name in which the user-defined data type was created. Otherwise, NULL is returned. DOMAIN_SCHEMA nvarchar(128) If the column is a user-defined data type, this column is the creator of the user-defined data type. Otherwise, NULL is returned. DOMAIN_NAME nvarchar(128) If the column is a user-defined data type, this column is the name of the user-defined data type. Otherwise, NULL is returned.
系統時間:2024-06-02 0:54:42
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!