一对多关系的查找表?
我知道当我们处理多对多关系时,查找表是必要的。
但是一对多关系怎么样 - 我们是否需要在其中一个表中使用查找表或外键?
另外一个问题,一对多和多对一一样吗?
I understand that a lookup table is necessary when we are dealing with many-to-many relationship.
But what about one-to-many relationship - do we need a lookup table or a foreign key in one of the tables?
Another question, is one-to-many the same as many-to-one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要一对多关系的查找表,该关系的“多”表中的外键列就足够了。
一对多和多对一关系在结构上是相同的,只是彼此的镜像。
因此,您可能会说博客文章及其评论处于一对多关系(其中外键位于“多”,在本例中为“评论”)。或者您可以说评论和他们的博客文章处于多对一关系(同样,外键位于“多”上)。无论哪种方式,数据库结构都是相同的,没有查找表,并且外键列位于“许多”上。
You don't need a lookup table for one-to-many relationships, a foreign key column in the "many" table of this relationship will suffice.
One-to-many and many-to-one relationships are structurally the same, just mirror images of each other.
So you might say that a blog post and its comments are in a one-to-many relationship (where the foreign key is on the "many", in this case "comments"). Or you could say that comments and their blog post are in a many-to-one relationship (again, with the foreign key on the "many"). Either way, the db structure is the same, with no lookup table, and with the foreign key column on the "many".