2

We have a problem with our database design. We've had to break our customer contact information schema into separate tables : Phone table,Email table, Fax table etc and we then have a many-to-many relationship between the main customer table and the different contact tables.

For example customers can have many phone numbers if the customer works in different locations and shares different bits of contact information with other customers. I am trying to decide between creating a generic table to hold all form of contacts data in and have lookup table for contacts_types field with tag values like personal, email,work email,home phone ,cell phone, work phone , home fax ,work fax,work website etc.

Which design would you advise?

4

4 に答える 4

2

As someone who has done database work for many years, create the separate tables. In the first place, eventually you may want different fields (I know our phone table and email table have different structures). In the second place the model you describe is an EAV model and it generally is a poor choice for both performance and data integrity (it becomes hard to enforce all the FKs you need).

I would never use an EAV table unless it was something so variable (like the details of all the possible medical tests) that I had no other choice.

于 2012-10-05T17:21:05.923 に答える
0

このようなデータベースを設計するには、テーブルとの多対多の関係を作成する必要があります。必要になるだろう

連絡先
1---*電話*---1電話タイプ
1---*電子メール*---1電子メールタイプ

電話やメールを他の連絡先と共有する必要がある場合は、次のようにします。

連絡先
*---*電話*---1PhoneType
*---*電子メール*---1 EmailType

これは基本的なデータベース設計です。より多くのアイデアを与えるために、いくつかの例を読むことをお勧めします。

編集:役立つ簡単な図を見つけました:http: //imar.spaanjaars.com/Images/Articles/N-LayerDesign/DatabaseDiagram.jpg

完全な例は、「設計-要件の収集」セクション http://imar.spaanjaars.com/416/building-layered-web-applications-with-microsoft-aspnet-20-part-1にあります。

参照テーブルが必要な場合は、PhoneType(Home Fax、Work Fax、Home Phoneなど)またはEmailType(Home、Work)テーブルを追加できます。

于 2012-10-05T13:38:04.113 に答える
0

A person can have zero or more addresses, and an address can be used by zero or more people. The address assignment can change over time.

This is the correct answer:

Party -< PartyAddress >- Address

PartyAddress{
  partyId
  addressId
  fromDate
  toDate (nullable)
  label -> [work, home, fax, ...]
  extension (nullable)
}

TelephoneNumber : Address
EmailAddress : Address
WebSite : Address
MailingAddress : Address

It is useful to abstract address for sales order processing. That way you can fulfill an order to an email address if you want. Also makes it easy to "list all communication methods with this contact"

于 2012-10-05T18:04:20.990 に答える
-1

It reads like you need a 'contacts' table:

contact id
customer id
first name
surname
... other fields which would have only one value per contact

And also a phone table

contact id
phone number
phone type (home, office, mobile, fax)

Presumably the primary key of this table would be phone number, as this is supposed to be unique (the problem would be people entering false phone numbers)

I would think that each contact would have only one email address - whilst I have three addresses, one is for work, one is for home and one is for spam. In a work situation, I would only give my work email so this is the one to be stored in the 'contacts' table.

This schema allows you multiple contacts per customer, and multiple phone numbers per contact.

于 2012-10-05T15:47:06.747 に答える