In the SQL, we need to write a lot, multi-level join. but the problem is, we don't now how to connect those tables?
在SQL中,我们需要编写很多,多级连接。但问题是,我们现在不怎么连接这些表?
For example, Table_A
reference Table_B
, Table_B
reference Table_C
using foreign key. How to get all this relationship route map? Do we have a free open souce tool to get relationship between ANY two tables if applicable?
例如,Table_A引用Table_B,Table_B引用Table_C使用外键。如何获得所有这些关系路线图?我们是否有免费的开源工具来获取任何两个表格之间的关系(如果适用)?
I prefer Java code.
我更喜欢Java代码。
3 个解决方案
#1
1
You can use SQL Power Architect to obtain a data model by reverse engineering a database. The Community Edition is capable of doing it.
您可以使用SQL Power Architect通过反向工程数据库来获取数据模型。 Community Edition能够做到这一点。
#2
1
I maybe you mean how to get foreign key from metadata. Basically foreign keys defines realations.
我可能你的意思是如何从元数据中获取外键。基本上,外键定义了重新绑定。
Here is an example how to get foreign keys from jdbc metadata: http://www.java2s.com/Code/Java/Database-SQL-JDBC/GetForeignKeys.htm
以下是如何从jdbc元数据获取外键的示例:http://www.java2s.com/Code/Java/Database-SQL-JDBC/GetForeignKeys.htm
Also you can use hibernate tools to reverse engineer database to domain entities. Where you can clearly see relations.
您还可以使用hibernate工具将数据库反向工程到域实体。在哪里可以清楚地看到关系。
#3
0
java.sql.DatabaseMetaData interface exposes meta information about the database. Specifically this method exposes foreign key relationships:
java.sql.DatabaseMetaData接口公开有关数据库的元信息。具体来说,此方法公开了外键关系:
public ResultSet getCrossReference(String primaryCatalog,
String primarySchema,
String primaryTable,
String foreignCatalog,
String foreignSchema,
String foreignTable)
throws SQLException
Java doc:
Retrieves a description of the foreign key columns in the given foreign key table that reference the primary key columns of the given primary key table (describe how one table imports another's key). This should normally return a single foreign key/primary key pair because most tables import a foreign key from a table only once.
检索给定外键表中引用给定主键表的主键列的外键列的描述(描述一个表如何导入另一个键的键)。这应该通常返回单个外键/主键对,因为大多数表只从表中导入一次外键。
#1
1
You can use SQL Power Architect to obtain a data model by reverse engineering a database. The Community Edition is capable of doing it.
您可以使用SQL Power Architect通过反向工程数据库来获取数据模型。 Community Edition能够做到这一点。
#2
1
I maybe you mean how to get foreign key from metadata. Basically foreign keys defines realations.
我可能你的意思是如何从元数据中获取外键。基本上,外键定义了重新绑定。
Here is an example how to get foreign keys from jdbc metadata: http://www.java2s.com/Code/Java/Database-SQL-JDBC/GetForeignKeys.htm
以下是如何从jdbc元数据获取外键的示例:http://www.java2s.com/Code/Java/Database-SQL-JDBC/GetForeignKeys.htm
Also you can use hibernate tools to reverse engineer database to domain entities. Where you can clearly see relations.
您还可以使用hibernate工具将数据库反向工程到域实体。在哪里可以清楚地看到关系。
#3
0
java.sql.DatabaseMetaData interface exposes meta information about the database. Specifically this method exposes foreign key relationships:
java.sql.DatabaseMetaData接口公开有关数据库的元信息。具体来说,此方法公开了外键关系:
public ResultSet getCrossReference(String primaryCatalog,
String primarySchema,
String primaryTable,
String foreignCatalog,
String foreignSchema,
String foreignTable)
throws SQLException
Java doc:
Retrieves a description of the foreign key columns in the given foreign key table that reference the primary key columns of the given primary key table (describe how one table imports another's key). This should normally return a single foreign key/primary key pair because most tables import a foreign key from a table only once.
检索给定外键表中引用给定主键表的主键列的外键列的描述(描述一个表如何导入另一个键的键)。这应该通常返回单个外键/主键对,因为大多数表只从表中导入一次外键。