Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have tables person which stores all information about a person.
Another table contact which stores contact info about table person.
Contact has column "contactid" which is referenced from table person.

And another table " emergency contacts" which stores emergency contacts of a person.
How do I achieve the following
1. the emergency contact of personA -(personB) may already exist in Person table who also have contact info. When personB contact info is deleted the reference in emergency table should be delete and also cascade upon update of personB's contact info.
2.the emergency contact of personA may not already exist in table Person.

Thanks.
Posted

1 solution

Have one person table to store all people and one table to store all the references. Before deleting a person record, delete all the references.

Person

Name  ...
Alice ...
Bob   ...


Reference

From  To  ...
Alice Bob ...


(I would never use names (or other strings) as IDs, but you get the idea.)

The reference table can also hold an indicator of what type of reference it is -- such as emergency contact, or authorized buyer, or whatever you need.
 
Share this answer
 
v2
Comments
kwaku Emma 19-Nov-15 20:19pm    
Yes I get your idea but is it necessary to store those emergency contacts who don't have records in person (this stores records that have vital functions)
PIEBALDconsult 19-Nov-15 20:26pm    
They are persons; you put them in person. You may have an indicator (perhaps bitmapped) for what kind of person, but all persons go in one table. Doing otherwise leads to unnecessary complexity. What happens when one person should exist in both tables? Or be moved from one to the other?
You asked for advice from experienced developers; this is the advice from an experienced developer.
kwaku Emma 20-Nov-15 4:42am    
Sorry. I didn't mean to be rude but wanted know if my thinking is close to correctness. I appreciate your effort. Thanks

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