I am creating an application (desktop) to store and retrieve patients’ records along with diseases. As patients and diseases have a many to many relationship, so I’ve created three tables; PATIENTS, DISEASES and one is Junction table. As one patient can register more than once in a single disease over the time so ‘PATIENTS’ table contains composite primary key of patient’s ‘reference no’ and ‘registration date’. Table ‘DISEASES’ only contains ‘name’ as a primary key.
Now I am a little confused about the design of junction table. It is containing the composite primary key of ‘PATIENTS’ table and a primary key of ‘DISEASES’ table as foreign keys.
Should I make composite primary key of all these foreign keys in junction table or create another primary key or something different?
Any help would be greatly appreciated.
I would suggest you one more table for cases. This table would contain an entry date. You should not use the disease name as primary key. This would make it difficult to correct typos or simply to choose a more appropriate name in the future, or maybe you would want to have a Latin as well as an English name.
Patient table ------------- PK PatientID Name DateOfBirth etc.Disease table ------------- PK DiseaseID NameCase table ------------- PK CaseID FK PatientID EntryDate etc.Now you have these relations
EDIT:
The case table might not be necessary for now and might seem to be over-designed. However, should it turn out in future, that you have to store other data to a case as well; the db design would not have to be changed fundamentally.
UPDATE:
Alternatively, you could do it without a case table. In that case, the junction table would have a date as part of the primary key
The relations would be