如何列出資料庫完整的結構 |
答題得分者是:timhuang
|
bestlong
站務副站長 發表:126 回覆:734 積分:512 註冊:2002-10-19 發送簡訊給我 |
想用程式列出資料庫的結構, 目前用 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 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
bestlong
站務副站長 發表:126 回覆:734 積分:512 註冊:2002-10-19 發送簡訊給我 |
引言: 列出 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 發送簡訊給我 |
引言: 可使用 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 發送簡訊給我 |
參考: 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 發送簡訊給我 |
|
Rain
資深會員 發表:31 回覆:236 積分:268 註冊:2003-02-17 發送簡訊給我 |
書裏邊怎麼做?
下面也是一種方法:取得完整的資料庫結構
執行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.
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |