c#
中如何獲取資料庫中表的資訊和列的資訊
獲取表的資訊:
conn.open();
string
restrictions = new
string[4];
restrictions[1] = "dbo";
datatable
table = conn.getschema("tables", restrictions);
conn.close();
返回的table是表的所有資訊,而不僅僅是名字,可以通過如下語句檢視這些資訊:
foreach
(system.data.datarow row in table.rows)
= ", col.columnname, row[col]); }
}要獲取指定表的資訊,關鍵是要設定陣列
restrictions
的值。對於表而言,這個陣列有如下的含義:
restriction[0]
表示表所在的
catalog
restriction[1]
表示表的所有者
restriction[2]
表示表的名字
restriction[3]
表示表的型別:
上面的例子就獲取了所有
dbo擁有的表的資訊。如果要獲取所有的使用者表,而非系統表,可用如下語句:
conn.open();
string
restrictions = new
string[4];
restrictions[3] =
「base table"
;datatable
table = conn.getschema("tables", restrictions);
conn.close();
獲取列的資訊:
conn.open();
string
restrictions = new
string[4];
restrictions[1] = "dbo";
datatable
table = conn.getschema("columns", restrictions);
conn.close();
與獲取表的**很類似,只是
getschema
的第乙個引數不同。同樣,返回結果取決於
restriction
的值。此時,
restriction[0]
表示列所在的
catalog
restriction[1]
表示列的所有者
restriction[2]
表示列所在的表的名字
restriction[3]
表示列名
例如:// restriction string array
string res = new string[4];
// dbo
擁有的所有表的所有列的資訊
res[1] = "dbo";
datatable t1 = conn.getschema("columns", res);
// 任意
owner/schema
所擁有的乙個叫
authors
的表的列資訊
res[2] = "authors";
datatable t2 = conn.getschema("columns", res);
//任意
owner/schema
所擁有的乙個叫
authors
的表的列
name
的資訊
res[2] = "authors";res[3] = "name ";
datatable t3 = conn.getschema("columns", res);
//任意
owner/schema
任意表中的乙個列名是
name
的列的資訊。
res[3] = "name";
datatable t4 = conn.getschema("columns", res);
獲取資料庫的其它資訊都可以使用
getschema
,只是第乙個引數不同。這個引數在不同的資料庫有差異: 1
、在sql server
中,可以獲取的架構集合如下: ·
databases ·
foreignkeys ·
indexes ·
indexcolumns ·
procedures ·
procedureparameters ·
tables ·
columns ·
users ·
views ·
viewcolumns ·
userdefinedtypes 2
、在oracle
中,可以獲取的架構集合如下: ·
columns ·
indexes ·
indexcolumns ·
procedures ·
sequences ·
synonyms ·
tables ·
users ·
views ·
functions ·
packages ·
packagebodies ·
arguments ·
uniquekeys ·
primarykeys ·
foreignkeys ·
foreignkeycolumns ·
procedureparameters
----
ORACLE如何同步資料庫中表資訊
oracle快照原理及實現總結 oracle資料庫的快照是乙個表,它包含有對乙個本地或遠端資料庫上乙個或多個表或檢視的查詢的結果。對於中大型資料庫,業務資料庫裡所有的資料同步到另外乙個處理伺服器上最佳的選擇還是使用snapshot方式,即快照的方式。由於工作需要,今天需要將業務資料庫裡所有的資料同步...
查詢資料庫中表的資訊
select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.value,else end,字段序號 a.colorder,欄位名 a.name,標識 case when ...
獲取資料庫中表名
用的老舊的assess資料庫,用sql語句獲取的方式是 select name from msysobjects where type 1 and flags 0 跟其他資料庫差異很大,而且這msysobjects還是乙個系統隱藏物件,程式想用這種方法的話,要到assess安全設定裡設定允許msys...