Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three tables in my database:
doctor(DoctorCode,Name,...)
nurse(NurseCode,Name,...)
accounting(PersonCode,date,...)
that personCode refers to DoctorCode and NurseCode but when I want to insert values to accounting table , the DoctorCode value and NurseCode value must be same.
is there a standard way to solve the problem?
Posted

1 solution

The problem comes from the fact that you have split the persons into two separate tables.

So instead of having separate Doctor and Nurse table, replace them with a single Person table and add a column which identifies if the person is a doctor or a nurse.

So the person could be something like
Person
------
- PersonCode
- PersonType (e.g. 1=doctor, 2=nurse)
- Name
- ...


The foreign key reference in Accounting would now point only to person table.
 
Share this answer
 
v2
Comments
daneshjooha 27-Jul-15 1:02am    
if the features of doctor table or nurse table change in future or if the features of doctor table differs from nurse table .
now how can I solve the problem?
Wendelius 27-Jul-15 3:49am    
If the differences are quite small, I'd still use the same table and accept the fact that not every column is filled in every case.

On the other hand if the differences become too dominating, why not create an 'extension' table for nurse (or doctor) and locate the type specific fields in it. The relation to person table would be 1:1.

Third option could be to create a new child table for Person table and list the properties in it as rows, not columns. However, depending on the situation this may lead to overly complicated queries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900