Run
Run

Reputation: 57226

A lookup table for one-to-many relationship?

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?

Upvotes: 4

Views: 2906

Answers (1)

Ben Lee
Ben Lee

Reputation: 53349

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

Upvotes: 4

Related Questions