简体   繁体   English

多对多无联接表

[英]Many-to-many without join table

I have a Template and Comment table. 我有一个模板和注释表。

Template has two fields ID and KEY , I can have multiple versions of a template with the same KEY but different ID . 模板有两个字段IDKEY ,我可以有一个模板的多个版本,它们具有相同的KEY但具有不同的ID For example: 例如:

ID   1  2  3
KEY  1  1  1

And a Comment table with a ID column: 还有带有ID列的Comment表:

ID             1  2  3
TEMPLATE_KEY   1  1  1

Is it possible to do a many-to-many between Template and Comment like Template(key) <-> Comment(ID) without a join table ? 是否可以在没有连接表的情况下在Template和Comment之间进行多对多操作,例如Template(key) <-> Comment(ID)

ManyToMany is never possible without an additional table in a relational database. 没有关系数据库中的附加表,ManyToMany永远不可能。 Why would one want to avoid such a table at all? 为什么要完全避免使用这样一张桌子?

It is possible to do this but a join table will make referential integrity reasonable to enforce. 可以执行此操作,但是联接表将使引用完整性合理地强制实施。 You could store foreign key arrays on both sides, code triggers to manage them, and the like and if you do a delete, you will have a lot of proboems..... 可以在两边存储外键数组,管理它们的代码触发器等,如果执行删除操作,您将遇到很多麻烦。

Now, it is possible that in 9.4, this will be natively supported but it isn't there yet and the patches are still under discussion. 现在,很可能在9.4中将提供本机支持,但尚不支持,补丁仍在讨论中。 In general though, usually it is better to just go through join tables. 通常, 通常最好只通过联接表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM