martin
martin

Reputation: 13

DB design - FK for 1:1 tables

I have 2 tables, both relate to eachother as 1:1 -> Country and National_Anthem. Both are in separate tables because I need to store their own metadata.

Now does the FK of Country go in the National_Anthem table OR does the FK of National_Anthem go in the Country table? Since this is 1:1, i guess it can work eitherway?

Upvotes: 1

Views: 78

Answers (3)

Damir Sudarevic
Damir Sudarevic

Reputation: 22187

The basic 1:1 would be:

enter image description here

However, national anthems may change, so:

enter image description here

Upvotes: 1

Oren A
Oren A

Reputation: 5880

I agree with @John Zwinck it's subjective, and I would do it the other way around.
Because a National Anthem kind of "belongs" to a country, and if I had a class for each, probably the Country class would have had a NationalAnthem as a property (and so this should be reflected in the DB). But I can't say that's the absolute right answer, and @John has much sense in what he's saying.

Upvotes: 0

John Zwinck
John Zwinck

Reputation: 249153

This seems subjective, but I would put the link to the country in the anthem table, because I think a national anthem is sort of defined by its country, rather than the other way around. Also a country will have many properties similar to its national anthem (official language for example), and it would be impractical to have all of them reflected in a single table.

Upvotes: 3

Related Questions