开发者

A lookup table for one-to-many relationship?

开发者 https://www.devze.com 2023-04-12 06:30 出处:网络
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 ta

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?

Anoth开发者_StackOverflow社区er question, is one-to-many the same as many-to-one?


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号