我需要编写代码来学习有关几个数据库的一些信息。我们的客户将执行代码,因此我无法“在线”调整它。 数据库将是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
答案 0 :(得分:0)
你有一些选择。
使用ODBC或JDBC等技术,您可以使用其API来阅读此类信息。如果您使用JDBC,则DatabaseMetaData
:
http://docs.oracle.com/javase/8/docs/api/java/sql/DatabaseMetaData.html
您可以通过SQL查询数据库使用的架构信息。我在我的工具中使用这样的查询,将数据库模式转储到文本文件:https://code.activestate.com/recipes/576621-dump-informix-schema-to-text/?in=user-186902。对于Informix,表名的qyerying如下所示:
SELECT tabname
FROM systables
WHERE tabtype='T'
AND tabid >= 100
AND tabname[1] <> '_'
ORDER BY tabname