derby 是IBM捐赠给apache的java数据库实现,具有查询速度快和使用简单等特点,cloudscape是derby的IBM官方维护版本。通过一段时间的使用,对cloudscape有了一些浅显的认识,不敢独享,现总结如下:
1. derby & cloudscape 常用操作
- 查询数据库中的表:
derby & cloudscape可以看作是IBM DB2的一个微缩版(当然还有DB2 Express版,这个免费
),其操作比较类似于DB2,但是有一些常用操作的功能并没有提供,例如列出数据库中某个模式(DB2的概念,类似于oracle的user)下的所有表等等。
1) 查询所有模式下的所有的用户表
select s.schemaname || '.' || t.tablename from sys.systables t, sys.sysschemas s where t.schemaid = s.schemaid and t.tabletype = 'T' order by s.schemaname, t.tablename |
sys.systables 和 sys.sysschemas是两个系统表,存储的信息显而易见。
2) 查询所有表的所有键,包括主键和外键,不过比较难于识别
select t.tablename, conglomeratename backIdxName, cst.constraintname, cst.type from sys.systables t, sys.sysconstraints cst, sys.sysconglomerates cgl, sys.syskeys sk where isindex = 'TRUE' and cgl.tableid = t.tableid and (sk.constraintid = cst.constraintid and cst.type = 'P' and sk.conglomerateid = cgl.conglomerateid) and t.tableid = cst.tableid and t.tabletype = 'T' UNION select t.tablename, conglomeratename backIdxName, cst.constraintname, cst.type from sys.systables t, sys.sysconstraints cst, sys.sysconglomerates cgl, sys.sysforeignkeys fk where isindex = 'TRUE' and cgl.tableid = t.tableid and (fk.constraintid = cst.constraintid and cst.type = 'F' and fk.conglomerateid = cgl.conglomerateid) and t.tableid = cst.tableid and t.tabletype = 'T' order by tablename, type |
- 辅助工具
derby & cloudscape提供的ij命令行工具实在是不敢恭维,幸好IBM提供了Cloudscape WorkBench这个免费的工具,这个工具是基于eclipse的图形化工具,能够为DB2,Clouscape和derby提供比较方便的操作界面。
下载地址:http://www-128.ibm.com/developerworks/db2/downloads/csworkbench/