当然有啊,DatabaseMetaData meta = ...; meta.getExportedKeys/getImportedKeys 得到外键和被引用的外键 meta.getPrimaryKeys 得到主键
Listing All Table Names in a Database try { // Gets the database metadata DatabaseMetaData dbmd = connection.getMetaData();
// Specify the type of object; in this case we want tables String[] types = {"TABLE"}; ResultSet resultSet = dbmd.getTables(null, null, "%", types);
// Get the table names while (resultSet.next()) { // Get the table name String tableName = resultSet.getString(3);
// Get the table's catalog and schema names (if any) String tableCatalog = resultSet.getString(1); String tableSchema = resultSet.getString(2); } } catch (SQLException e) { }
SELECT table_name FROM User_tables t WHERE NOT EXISTS (SELECT table_name FROM User_constraints c WHERE constraint_type = 'P' AND t.table_name=c.table_name)其它相关数据字典解释 user_tables 表 user_tab_columns 表的列 user_constraints 约束 user_cons_columns 约束与列的关系 user_indexes 索引 user_ind_columns 索引与列的关系
meta.getExportedKeys/getImportedKeys 得到外键和被引用的外键
meta.getPrimaryKeys 得到主键
// Gets the database metadata
DatabaseMetaData dbmd = connection.getMetaData();
// Specify the type of object; in this case we want tables
String[] types = {"TABLE"};
ResultSet resultSet = dbmd.getTables(null, null, "%", types);
// Get the table names
while (resultSet.next()) {
// Get the table name
String tableName = resultSet.getString(3);
// Get the table's catalog and schema names (if any)
String tableCatalog = resultSet.getString(1);
String tableSchema = resultSet.getString(2);
}
} catch (SQLException e) {
}
FROM User_tables t
WHERE NOT EXISTS
(SELECT table_name
FROM User_constraints c
WHERE constraint_type = 'P'
AND t.table_name=c.table_name)其它相关数据字典解释
user_tables 表
user_tab_columns 表的列
user_constraints 约束
user_cons_columns 约束与列的关系
user_indexes 索引
user_ind_columns 索引与列的关系
楼上的错了吧,SQL语句应该不是楼主要的
1 怎么拿constraints?
2 遍历整个库?虽然是遍历的是表名,不是数据,但性能也太慢了吧,我的库几千张表啊----------------------------------------------------------------------
回复人: masse(当午) ( ) 信誉:100 2005-12-16 10:11:00 得分: 0
Listing All Table Names in a Database try {
// Gets the database metadata
DatabaseMetaData dbmd = connection.getMetaData();
// Specify the type of object; in this case we want tables
String[] types = {"TABLE"};
ResultSet resultSet = dbmd.getTables(null, null, "%", types);
// Get the table names
while (resultSet.next()) {
// Get the table name
String tableName = resultSet.getString(3);
// Get the table's catalog and schema names (if any)
String tableCatalog = resultSet.getString(1);
String tableSchema = resultSet.getString(2);
}
} catch (SQLException e) {
}
ResultSet resultSet = dbmd.getTables(null, null, "%"+tablename, types);
按表名