priya
priya

Reputation: 26689

Does it make sense to add foreign key relationship(s) to many-to-many tables

create table foo (id, name)
create table bar (id, name)
create table foo_bars (foo_id, bar_id)

Does it make sense to add foreign key relationship(s) to many-to-many tables. I am assuming we would need a FK relationship for foo_id and bar_id in foo_bars. Can someone confirm?

Upvotes: 0

Views: 51

Answers (2)

Oleg
Oleg

Reputation: 2821

Yes, you need foreign keys to ensure data consistency.

Upvotes: 2

zmbq
zmbq

Reputation: 39013

It makes a lot of sense. Do it.

Upvotes: 2

Related Questions