两个不同数据库中的两个表之间的多对多关系 [英] Many-to-Many Relationship between two tables in two different databases

查看:270
本文介绍了两个不同数据库中的两个表之间的多对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题中所述,是否可以在属于两个不同数据库的两个表之间创建多对多关系?如果是,我该如何使用PostgreSQL执行该操作?

As mentioned in the title, is it possible to create many-to-many relationship between two tables that belong to two different databases? If yes, how can i perform that with PostgreSQL?

推荐答案

使用外键约束来强制引用完整性的标准方法只是相同数据库中的可能 -不是数据库集群。但是您可以在同一个数据库中跨多个 schemas 操作。

The standard way of using foreign key constraints to enforce referential integrity is only possible within the same database - not db cluster. But you can operate across multiple schemas in the same database.

除此之外,您可以创建表以同样的方式。甚至可以使用 dblink FDW 。但是,RDBMS不能保证跨数据库的引用完整性。
另一个数据库是在同一物理计算机上,还是在同一数据库集群中,都无关紧要-这只会使连接更快,更多。安全。

Other than that, you can create tables just the same way. And even join tables dynamically among remote databases using dblink or FDW. Referential integrity cannot be guaranteed across databases by the RDBMS, though.
Does not matter much whether the other DB is on the same physical machine or even in the same DB cluster - that just makes the connection faster and more secure.

或者您可以将数据复制到一个公共数据库,并在其中添加标准约束。

Or you can replicate data to a common database and add standard constraints there.

这篇关于两个不同数据库中的两个表之间的多对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆