Reputation: 321
I have two tables
Person
{ ID, name, ... }PeopleInfected
{ PersonId, Infected } - this is always a one-to-one mappingIs it ok to use PersonId
as a primary key in the PeopleInfected
table or should I create a separate Id
column for PeopleInfected
.
I want to keep PeopleInfected
on another table since I don't want to fill Person
with this sort of information.
Upvotes: 1
Views: 2170
Reputation: 881
This is called vertical partitioning, and there could be a few reasons to do it, although "saving space" (btw, nulls don't take up much space) is not really the most common reason (a better reason is different access patterns to the data) .
The usual way to do vertical partitioning is using foreign keys, but it should be OK (ish) to use the same ID (without foreign keys).
A possible problem is that sometimes the ID is generated automatically by the RDBMS or the ORM (e.g. entity framework), and it might not be simple to force it to use a specified ID. Another possible problem is that you are forced to insert first into the Person table.
Upvotes: 2
Reputation: 46323
Yes it is OK. It's usually more common to combine the 2 tables, but if you have a specific reason not to do so (for example, low fill rate for the secondary table) it's fine
Upvotes: 1