Phonebook database design
I am designing database for web base(ASP.NET) Phone-book - Contact manager software.
Each contact may has different phone types .. (Home , Work , Mobile ,etc ...) here is my database design : Phone type contains for example :- Home
- Work
- Emergency or anything user wants.
I think I'll have problem with this design that I can't displaying contacts with all their numbers In a grid to user. What is your suggestion ?
You can do that with a simple query.
select c.contactid, c.contactname,
pt.typetitle,
pn.phoneno
from contact c
inner join phonenumber pn on pn.contactid = c.contactid
inner join phonetype pt on pt.phonetypeid = pn.phonetype
For data integrity, you're going to need some UNIQUE constraints in addition to your primary key constraints. If I were you, I'd consider UNIQUE constraints on ContactName, TypeTitle, and the pair (ContactID, PhoneType). In fact, the pair (ContactID, PhoneType) is probably a better primary key than PhoneID; consider dropping PhoneID entirely.
精彩评论