如何避免多个表的关系M:M? [英] How to avoid multiple tables tables to relations M: M?

查看:107
本文介绍了如何避免多个表的关系M:M?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何避免多个表格关系M:M?

How to avoid multiple tables tables to relations M: M?

查看下一个模型

< img src =https://i.stack.imgur.com/Ryl1b.pngalt =enter image description here>

多选择我创建了几张桌子,我一直运行良好,但现在我有很多情况将会发生。有一个解决方案,而不必创建这么多表?

As can be seen by each multiple choice I create a couple of tables, that I have always worked well, but now I have lots of situations where this is going to happen. there is a solution without having to create that number of tables?

注意:显然我们必须牢记,解决方案并没有使未来复杂化

Note:Obviously we must bear in mind that the solution does not complicate future queries, select, sort and query multiple tables that mix when reporting

推荐答案

如果您的优先级是避免链接表的激增,则查询,选择,排序和查询多个表,您可以使用继承(aka。category,subclassing,generalization hierarchy):

If your priority is avoiding the proliferation of the link tables, you can use inheritance (aka. category, subclassing, generalization hierarchy):

无论有多少个子实体项目有,你总是需要只有一个链接表( PersonItem )。

No matter how many child entities Item has, you always need only one link table (PersonItem).

不幸的是,今天的DBMS通常不会直接支持继承, d必须使用这3个策略中的一个表中的所有类或每个表的类手动表示它( 每个表的具体类仍然会增加链接表)。这在某些情况下会增加复杂性,所以如果您的优先级保持简单,您可能更好地遵守当前的设计(尽管这取决于您打算运行的查询的种类 - 一些可能实际上更简单的继承)

Unfortunately, inheritance is typically not directly supported by today's DBMSes so you'd have to represent it manually using either "all classes in one table" or "class per table" of these 3 strategies ("concrete class per table" would still proliferate link tables). This will increase the complexity in some cases, so if your priority is keeping queries simple, you are probably better off sticking with the current design (though this depends on the kinds of queries you intend to run - some may actually be simpler with inheritance).

BTW,上述模式不会让不同的 Hobby Thing 共享相同的 Id 。我猜这对你来说并不重要,但是如果是这样的话,这是没有继承的模型的一个论据(,你需要在项目的PK)。

BTW, the model above will not let different Hobby and Thing share the same Id. I'm guessing this is not important to you, but in case it is, this is an argument for the model without inheritance (or you'd need to include the type in the Item's PK).

这篇关于如何避免多个表的关系M:M?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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