Reputation: 7025
I have one table called Player
I want to create another table that has a 1 to 1 relationship to Player named PlayerExtraInfo to contain some columns. So I have several options:
Instead of creating a new table, add PlayerExtraInfo columns to Player table
Create PlayerExtraInfo table and have a FK in Player table.
Player table
PlayerExtraInfo table
The opposite: PlayerExtraInfo contains a FK to Player table. To get sure that relationship remains 1 to 1 I add a unique constrain.
Player table
PlayerExtraInfo table
Similar to option 3 but mixing PK and FK in one. In this case my foreign key becomes also the primary key:
Player table
PlayerExtraInfo table
I know that options 1, 2 are correct, but due to performance problems I am option for option 3 or 4. And thinking about these 3 and 4 options some doubts about option 4 assault me: So my questions are:
Upvotes: 0
Views: 244
Reputation: 51644
When extending one table with another one it is absolutely fine (and recommended as well) to use the primary key as the foreign key.
Upvotes: 4
Reputation: 7267
While options 2,3,4 are correct, I would think that option 1 is the one that will give the best performance. Even when using using clustered indexes, an extra join is an extra join. Also a foreign key will degrade performance in respect to the targeted table (I admit that a large number of foreign keys will degrade it, and not one single).
Except the case where the extended table will have but a fraction of the main table's records, or the case where you would like the 2 tables on different partitions, I cannot think of a reason to have that table split into peaces.
Upvotes: 1