Sunteți pe pagina 1din 6

Database design - Multiple "Contact information" for different tables - Stack Overflow

Products less. Build more. Use Stack Overflow for Teams at work to share knowledge with your colleagues. Free 30 day trial. Start your trial.
Search
Customers

Database design - Multiple “Contact information” for different tables


Home
Use cases

Search…
PUBLIC
Ask Question
Log
StackinOverflow
Asked

Sign up

6 years, 3 months ago

Active
5 years, 9 months ago
Tags
Viewed
13k times
Users

Jobs
Blog
8
TEAMS

4
this?
What’s
I have a database with tables "person", "company", "shop", etc. Many of these tables must have "contact Ben Popper is the worst coder in the world:
information". The possibility to design this was asked in Database design - Similar Contact Information for Something awry with my array
Free 30 Day Trial
multiple entities
Now, in my database I leave a possibility to have a multiple addresses, multiple phones
and multiple emails to each contact data. This is my database schema: This week, #StackOverflowKnows fast planes,
math with dates, and code comments

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack


Exchange services

Did Stack Exchange cut the number of


negative comments nearly in half between…

An account of my meeting with the Stack


Overflow management team

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

So, I make an intermediate table "contact" as a simplest way to link a "contact information" to each
table.
My question: is it a good practice to do this and to have a table with only one row? Linked
database database-design relational-database contacts
3
Database design - Similar Contact Information for
share improve this question multiple entities
edited May 23 '17 at 12:34 1
Customer/Company Address/Phone Numbers

Community ♦
1 1 Related

asked Oct 28 '13 at 17:49


378
List of standard lengths for database fields
nb.ag
107 1 1 7
1166
1
How to list the tables in a SQLite database file that

https://stackoverflow.com/questions/19641661/database-design-multiple-contact-information-for-different-tables[2/17/2020 2:04:04 AM]


Database design - Multiple "Contact information" for different tables - Stack Overflow

Only one Row or only one Column?


– Stephen R
Mar 20 '18 at 22:57 was opened with ATTACH?

add a comment
280
Relational Database Design Patterns?
3 Answers active oldest votes

228
Schema for a multilanguage database

7
3

This is how I would design your database:


Database design - Similar Contact Information for
multiple entities
address_types
id unsigned int(P)
description varchar(10) // Mailing, Physical, etc. 0
Database design: user with contact information
addresses
id unsigned int(P)
line1 varchar(50) // 123 Main Street, etc. 670
line2 varchar(50) // Default NULL
city_id unsigned int(F cities.id)
Difference between scaling horizontally and
zip varchar(6) // 12345, A1A 1A1, etc.
vertically for databases
zip4 char(4) // Default NULL
lat decimal(10,8) // 13.12345678, etc.
lon decimal(11,8) // 110.12345678, etc.
1

cities
id unsigned int(P) Database design best practices - linking/junction
state_id unsigned int(F states.id) table with multiple references
name varchar(50) // Omaha, Detroit, Tampa, etc.
Hot Network Questions
companies
id unsigned int(P)
How to select numerical sublists?
name varchar(75) // IBM, Microsoft, RedHat, etc.
... How does apt upgrade running programs?

companies_addresses When is it appropriate to introduce a new layer of


id unsigned int(P) abstraction into a class hierarchy?
company_id unsigned int(F companies.id)
I'm not able to delete -> in {{x -> a}, {x -> b}, {x ->
address_id unsigned int(F addresses.id)
c,x->d}}
address_type_id unsigned int(F address_types.id)
What this Dog Grill Grilling Machine called in
companies_contacts everyday spoken english?
id unsigned int(P)
How to add some perspective to AI files placed in
company_id unsigned int(F companies.id)
InDesign
contact_id unsigned int(F contacts.id)
contact_type_id unsigned int(F contact_types.id) Can you Rappel with an Old Climbing Rope?

companies emails How to pass data pointer to subroutine to use with


Absolute,Y addressing?
In North America phone numbers look like this: CC-AAA-EEE-SSSS-XXXXXXX where CC is the country
Pulling back a functor, it becomes monadic
code, AAA is the area code, EEE is the exchange, SSSS is the station and XXXXX is the extension.
Has a woman ever defeated a reigning undisputed
World Chess Champion in classical chess?
contacts
id unsigned int(P) How do Aarakocra fly with a backpack?
country_code varchar(3)
area_code varchar(3) Find common substring that starts a set of strings
exchange varchar(3)
When should a company hire developers versus
station varchar(4) outsourcing them?
extension varchar(10) // Default NULL
If a portal scroll is cheap and easily available why
they are not used when one's life is in peril?
See ISO 3166-1.
What are the coloured rectangles in research
papers?
countries
How did Canada come to be the robotic arm
id char(2) // ca, mx, us, etc.
people?
iso3 char(3) // can, mex, usa, etc.
iso_num char(3) Paint 21 Squares of a 7×7 Board Without Forming
name varchar(44) // Canada, Mexico, United States, etc. a Rectangle

Position of a nested list


email_types
id unsigned int(P) Why is learning mathematics compulsory?
description varchar(10) // Personal, Work, etc.
Using self-service gas pumps in Israel - with
emails Hebrew-only interface
id unsigned int(P)
Where to store passport during day trip in foreign
address varchar(255) // support@ibm.com, etc.
country

shops Why is China interested in Socotra Rock?

https://stackoverflow.com/questions/19641661/database-design-multiple-contact-information-for-different-tables[2/17/2020 2:04:04 AM]


Database design - Multiple "Contact information" for different tables - Stack Overflow

id unsigned int(P)
name varchar(45) // Shop A, Shop B, etc. Is there a name for a chess variant where you are
... allowed to capture your own pieces?

Detect manual changes to an autogenerated C


shops_addresses header
id unsigned int(P)
shop_id unsigned int(F shops.id) Question feed
address_id unsigned int(F addresses.id)
address_type_id unsigned int(F address_types.id)

shops_contacts
id unsigned int(P)
shop_id unsigned int(F shops.id)
contact_id unsigned int(F contacts.id)
contact_type_id unsigned int(F contact_types.id)

shops_emails
id unsigned int(P)
shop_id unsigned int(F shops.id)
email_id unsigned int(F emails.id)
email_type_id unsigned int(F email_types.id)

See ISO 3166-2.

states
id unsigned int(P)
country_id char(2)(F countries.id)
code varchar(2) // AL, NF, NL, etc.
name varchar(50) // Alabama, Newfoundland, Nuevo León, etc.

share improve this answer

answered Oct 28 '13 at 19:34

Benny Hill
5,695 4 34 55

Ok, I see your point. You propose the same solution that here stackoverflow.com/questions/3636061/… (method 1). But
here a same disadvantage – "creation a lot of associative tables". There is another way to do this?
–  nb.ag
Oct 28 '13 at
22:55

It's really not a disadvantage, normalization is a good thing. RDBMS's are good at joining tables as long as you index things
properly.
– Benny Hill
Oct 29 '13 at 0:01

I know this is 2 years old, but I'm wondering what your thoughts are for putting the email_type_id on each of the
XXXX_emails tables rather than putting it on the email table since every email will have a type. I'm designing something
similar and came to a similar design as you (with the exception of not breaking the phone number out into as many
columns), except that I was going to put the email_type_id on the email table.
– kralco626
Nov 20 '15 at 16:16

@kralco626 - two years later I would design this slightly differently. I would put the email_type_id in the emails table
as you suggest but I would also remove the id column from the shops_addresses , shops_contacts and
shops_emails tables. I would change their respective primary keys to be a composite of shop_id and address_id ;
shop_id and contact_id ; and shop_id and email_id .
– Benny Hill
Nov 20 '15 at 18:06

add a comment

My question: is it a good practice to do this and to have a table with only one row?

Not really. Looking at your diagram, I have to ask : can a contact really be linked to an arbitrary number of
persons ? If not, you should use 'person' as your parent table and make the other tables link to it.
share improve this answer

answered Oct 28 '13 at 18:17

AurelienT

https://stackoverflow.com/questions/19641661/database-design-multiple-contact-information-for-different-tables[2/17/2020 2:04:04 AM]


Database design - Multiple "Contact information" for different tables - Stack Overflow

191 4

Actually yes, I can have a thousand persons, companies and shops. If I understand well your advice, I have to link directly
email, phone and address to all my entities (persons, companies, shops)? So I will have something like this: email ->
idemail, mail, idperson, idcompany, idshop Is it really better?
–  nb.ag
Oct 28 '13 at 18:26

No, in your case you should in fact use associative tables as suggested by Benny Hill below. It is possible to do otherwise,
but insuring the data stays coherent would be really annoying and not worth it.
– AurelienT
Oct 29 '13 at 0:34

also link country to address not to city, as there may be cities in different countries and/or states/province/county that has
same name
– AquaAlex
Oct 16 '14 at 8:06

add a comment

Personaly, i don't like realy this method because we need to create any Entity for each table and a lot of
associative tables. I propose one table for contact informations and another one for addresses.

informations
- id INT
- name VARCHAR
- value VARCHAR
- type ENUM(phone, email, url, custom)
- idcompany INT NULL
- idcontact INT NULL

And

addresses
- id
- address1
- address2
- district
- postcode
- idcity
- idcompany
- idcontact

share improve this answer

edited May 14 '14 at 23:49

answered May 14 '14 at 23:39

Youssef El Montaser
81 1 1 5

add a comment

Your Answer

https://stackoverflow.com/questions/19641661/database-design-multiple-contact-information-for-different-tables[2/17/2020 2:04:04 AM]


Database design - Multiple "Contact information" for different tables - Stack Overflow

Sign up or log in
Sign up using Google
Sign up using Facebook

Sign up using Email and Password

Post as a guest
Name

Email
Required, but never shown

Post
Post Your
Your Answer
Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged database database-design

relational-database contacts or ask your own question.

STACK OVERFLOW

Questions

Jobs

Developer Jobs Directory

Salary Calculator

Help

Mobile

Disable Responsiveness

PRODUCTS

Teams

Talent

Advertising

Enterprise

COMPANY

About

Press

Work Here

Legal

Privacy Policy

Contact Us

https://stackoverflow.com/questions/19641661/database-design-multiple-contact-information-for-different-tables[2/17/2020 2:04:04 AM]


Database design - Multiple "Contact information" for different tables - Stack Overflow

STACK EXCHANGE
NETWORK

Technology

Life / Arts

Culture / Recreation

Science

Other

Blog

Facebook
Twitter

LinkedIn
site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0
with attribution required.
rev 2020.2.15.36073

https://stackoverflow.com/questions/19641661/database-design-multiple-contact-information-for-different-tables[2/17/2020 2:04:04 AM]

S-ar putea să vă placă și