Owais F
Owais F

Reputation: 321

Use Primary key of one table on another table as a primary key

I have two tables

Is 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

Answers (2)

gen-y-s
gen-y-s

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

Amit
Amit

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

Related Questions