【发布时间】:2015-12-15 13:41:06
【问题描述】:
我需要编写代码来了解有关多个数据库的一些信息。执行代码的将是我们的客户,所以我将无法“在线”调整它。 数据库将是 Oracle(9、10、11)、DB2、AS400 DB2、Informix 和 MS SQL(2000 和 2008)。 我编写了 Oracle 所需的代码,但我对其他数据库一无所知。你能帮我为其他数据库复制它吗? 非常感谢!
1
select owner, count(*) -- number of tables in schemes
from all_tables
where owner not in ('SYS', 'SYSTEM', 'SYSMAN') and temporary = 'N'
group by owner
2
select atc.owner, atc.data_type, count(*) --number of tables by schemes and datatypes
from all_tab_columns atc
inner join all_tables t
on t.OWNER = atc.OWNER
and t.TABLE_NAME = atc.TABLE_NAME
where atc.owner not in ('SYS', 'SYSTEM', 'SYSMAN')
and t.temporary = 'N'
group by atc.owner, atc.data_type
3
select atcom.owner, count(*) --number of comments by schemes
from all_tab_comments atcom
inner join all_tables t
on t.OWNER = atcom.OWNER
and t.TABLE_NAME = atcom.TABLE_NAME
where atcom.comments is not null
and atcom.owner not in ('SYS', 'SYSTEM', 'SYSMAN')
group by atcom.owner
4
select owner, constraint_type, count(*) --number of constraints by schemes and types
from all_constraints ac
where status = 'ENABLED' and owner not in ('SYS', 'SYSTEM', 'SYSMAN')
group by owner, constraint_type
【问题讨论】:
-
查看 INFORMATION_SCHEMA。
-
您使用的是什么 API?如果您支持连接到许多不同的数据库,那么您很可能正在使用跨平台 API 来连接到数据库。如果是这种情况,该 API(ODBC、JDBC、OLE DB、ODP.Net 等)将提供执行此操作的函数,而不是为每个数据库编写特定的 SQL。
标签: sql oracle db2 ibm-midrange informix