此函数返回包含数据库的信息 RecordSet 对象,如数据库包含哪些表等。
connection.OpenSchema(QueryType [,Criteria] [,SchemaID]) |
参数 | 意义 |
---|---|
QueryType | 查询类型 |
Criteria | 查询限制条件数组,如 Array("DATA","TABLE"),不限定项设为空值 |
SchemaID | 提供者纲要查询的 GUID,一般不使用 |
QueryType 值 | Criteria 数值内容 | 说明 |
---|---|---|
Public Const AdSchemaAsserts = 0 |
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME |
|
Public Const AdSchemaCatalogs = 1 |
CATALOG_NAME '数据库名 | 返回数据库名 |
Public Const AdSchemaCharacterSets = 2 |
CHARACTER_SET_CATALOG CHARACTER_SET_SCHEMA CHARACTER_SET_NAME |
|
Public Const AdSchemaCollations = 3 |
COLLATION_CATALOG COLLATION_SCHEMA COLLATION_NAME |
|
Public Const AdSchemaColumns = 4 |
TABLE_CATALOG '数据库 TABLE_SCHEMA '所有者 TABLE_NAME '表 COLUMN_NAME '列 |
返回列名 |
Public Const AdSchemaCheckConstraints = 5 |
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME |
|
Public Const AdSchemaColumnDomainUsage = |
DOMAIN_CATALOG DOMAIN_SCHEMA DOMAIN_NAME COLUMN_NAME |
|
Public Const AdSchemaConstraintColumnUsage = 6 |
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME |
|
Public Const AdSchemaConstraintTableUsage = 7 |
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME |
|
Public Const AdSchemaKeyColumnUsage = 8 |
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME |
|
Public Const AdSchemaReferentialConstraints = 9 |
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME |
|
Public Const AdSchemaTableConstraints = 10 |
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE |
|
Public Const AdSchemaIndexes = 12 |
TABLE_CATALOG TABLE_SCHEMA INDEX_NAME TYPE TABLE_NAME |
|
Public Const AdSchemaColumnPrivileges = 13 |
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME GRANTOR GRANTEE |
|
Public Const AdSchemaTablePrivileges = 14 |
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME GRANTOR GRANTEE |
|
Public Const AdSchemaUsagePrivileges = 15 |
OBJECT_CATALOG OBJECT_SCHEMA OBJECT_NAME OBJECT_TYPE GRANTOR GRANTEE |
|
Public Const AdSchemaProcedures = 16 |
PROCEDURE_CATALOG '数据库 PROCEDURE_SCHEMA '所有者 PROCEDURE_NAME '存储过程 PROCEDURE_TYPE '过程类型 |
返回存储过程名 |
Public Const AdSchemaSchemata = 17 |
CATALOG_NAME SCHEMA_NAME '所有者 SCHEMA_OWNER |
返回数据库所有者 |
Public Const AdSchemaSQLLanguages = 18 |
<无> | |
Public Const AdSchemaStatistics = 19 |
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME |
|
Public Const AdSchemaTables = 20 |
TABLE_CATALOG '数据库 TABLE_SCHEMA '所有者 TABLE_NAME '表名 TABLE_TYPE '表类型 |
返回表 |
Public Const AdSchemaTranslations = 21 |
TRANSLATION_CATALOG TRANSLATION_SCHEMA TRANSLATION_NAME |
|
Public Const AdSchemaProviderTypes = 22 |
DATA_TYPE '类型名 BEST_MATCH |
返回数据类型 |
Public Const AdSchemaViews = 23 |
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME |
|
Public Const AdSchemaViewColumnUsage = 24 |
VIEW_CATALOG VIEW_SCHEMA VIEW_NAME |
|
Public Const AdSchemaViewTableUsage = 25 |
VIEW_CATALOG VIEW_SCHEMA VIEW_NAME |
|
Public Const AdSchemaProcedureParameters = 26 |
PROCEDURE_CATALOG '数据库 PROCEDURE_SCHEMA '所有者 PROCEDURE_NAME '过程名;n PARAMTER_NAME '参数名 |
返回存储过程参数 |
Public Const AdSchemaForeignKeys = 27 |
PK_TABLE_CATALOG PK_TABLE_SCHEMA PK_TABLE_NAME FK_TABLE_CATALOG FK_TABLE_SCHEMA FK_TABLE_NAME |
|
Public Const AdSchemaPrimaryKeys = 28 |
PK_TABLE_CATALOG PK_TABLE_SCHEMA PK_TABLE_NAME |
|
Public Const AdSchemaProcedureColumns = 29 |
PROCEDURE_CATALOG PROCEDURE_SCHEMA PROCEDURE_NAME COLUMN_NAME |
|
Public Const AdSchemaProviderSpecific = -1 |
参见说明 |
在 EXCEL 中,各工作表被认为是 SYSTEM TABLE,定义区域则为 TABLE。
字段名 | 意义 | 内容示例 |
---|---|---|
TABLE_CATALOG | 数据来源 | "c:\database\db1" |
TABLE_NAME | 表名 | "table1"、"查询1","Sheet1$" |
TABLE_TYPE | 表类型 | "SYSTEM TABLE"、"TABLE"、"VIEW" |
字段名 | 意义 | 内容示例 |
---|---|---|
TABLE_CATALOG | 数据库名 | tempdb |
TABLE_SCHEMA | 所有者 | "dbo" |
TABLE_NAME | 表名 | |
COLUMN_NAME | 字段名 | 重名加序号,回车换"_" |
ORDINAL_POSTION | 字段位置 | |
COLUMN_DEFAULT | 字段默认值 | 0,('') |
IS_NULLABLE | 允许空值 | True |
DATA_TYPE | 数据类型 | 3(整数) |
CHARACTER_MAXIMUM_LENGTH | 宽度 | 255 |
NUMERIC_PRECISION | 数字精度 | 10,5 |
DATETIME_PRECISION | 日期时间精度 | 9 |
字段名 | 意义 | 内容示例 |
---|---|---|
NAME | 类型名称 | int,char |
DATA_TYPE | 类型号 | 3,129 |
COLUMN_SIZE | 类型最大尺寸 | 10,8000 |
LITERAL_PREFIX | 类型左边界 | 无,"'" |
LITERAL_SUFFIX | 类型右边界 | 无,"'" |
LOCAL_TYPE_NAME | 本地类型名 | 同 NAME |
字段名 | 意义 | 内容示例 |
---|---|---|
PROCEDURE_CATALOG | 数据库 | asteras |
PROCEDURE_SCHEMA | 所有者 | dbo |
PROCEDURE_NAME | 存储过程;序号 | ast;1 |
PROCEDURE_TYPE | 过程类型 |
VisualBasic
set rec=cn.openschema(AdSchemaTables,array(null,null,null,"table")) '
返回所有表
set rec=cn.openschema( AdSchemaTables,array("ast",null,null,"table")) ' 返回 AST 库所有表 set rec=cn.openschema(AdSchemaTables,array(null,null,null,"view")) ' 返回所有视图 set rec=cn.openschema(AdSchemaTables) ' 返回所有存储过程 |
Delphi
rs := TADODataSet.Create(Self); adocn.OpenSchema(siTables,VarArrayOf([Unassigned,Unassigned,Unassigned,Unassigned]),EmptyParam,rs); |
检测某张表的信息,表不存在时返回空记录
function HasTable(cn:tadoconnection;tablename:string):Boolean; var rs : TADODataSet; begin rs := TADODataSet.Create(Self); cn.OpenSchema(siTables,VarArrayOf([Unassigned,Unassigned,tablename,'TABLE']),EmptyParam,rs); result := not rs.Eof; rs.Close; rs.Free; end; |
function HasTable(cn:_Connection;tablename:string):Boolean; var rs : _Recordset; begin rs := cn.OpenSchema(AdSchemaTables ,VarArrayOf([Unassigned,Unassigned,tablename,'TABLE']),EmptyParam); result := not rs.Eof; rs.Close; end; |
检测某张表的字段信息,字段不存在时返回空记录
rs := TADODataSet.Create(Self); cn.OpenSchema(siColumns,VarArrayOf([Unassigned,Unassigned,'tablename','columnname']),EmptyParam,rs); |