Given: A patient has many doctors and doctors have multiple patients.
What is the difference between the following two schemas?
- Option 1: Association Table
- Patient[id, data1]
- Doctor[id, data2]
- Patient_Doctor[patient_id, doctor_id]
- Option 2: A single foreign key
- Patient[id, data1, doctor_id]
- Doctor[id, data2]
The only thing I can think of is that option 2 requires you to duplicate data1 multiple times and if data1 is large performance will suffer. Is that correct?
No, that’s not correct. “Option 2”, in which patient.id is presumably the primary key, prevents you from inserting more than one row for each patient. So each patient can have one and only one doctor. That doesn’t work in the general case: a primary care doctor might refer a patient to an allergist, a gastroenterologist, an oncologist, and so on.
For fun, consider the fact that doctors themselves have doctors.