问题
I'm trying to design a normalized relational database where a patient has a *contact person* (person who is contacted in case of emergency). I also have a table called contact_num which takes patient_id as a foreign key. But how can I implement having a emergency contact person (who has a phone number) who may/may not be another patient? Should I implement emergency_contact_num table? Or some kind of unary relationship? egs would be helpful
回答1:
I think you could have a contacts book, all stored in a database
So for the patient, the entry into the database could be:
'id' => '1'
'first_name' => 'john'
'last_name' => 'doe'
'emergency_contact' => '2'
Of course, you should also include any important information about this person in this table (ex. Phone number). For the emergency contact, the database could be:
'id' => '2'
'first_name' => 'lisa'
'last_name' => 'joe'
'emergency_contact' => 'none'
回答2:
If your goal is normalization, then contact information is contact information regardless of what role the person plays in the operation. Go with the contact book suggestions, but don't include emergency contact, etc. A patient is a patient, and could have any number of details required that have nothing to do with contact information. At that point, you can either include emergency contact information as part of the primary patient table or, if you expect the possibility of multiple contacts for single patient, you could have a patient_Contact table that would contain the patient id from the patients table and the contact id for each contact listed. This would provide the maximum flexibility for contacts having multiple relations with different actors in the process simply by storing the cross reference.
So rather than including a patient as FK on the contact, include the contact id on the patient. you could also at that point include the patient contact data (their phone number, address, etc) on the contact table, and reference the contact id as PatientContact. now you only have one table storing Name, phone number, address, etc.
来源:https://stackoverflow.com/questions/16342959/relational-database-emergency-person-contact-number