Y
Y
Yugran2019-02-28 04:21:00
Database design
Yugran, 2019-02-28 04:21:00

What is the structure of the database for storing phones of people and companies?

There is a contact table for people and a contact table for companies.
A person can have several phones
A company can have several phones
One phone can have only one owner - a person or a company.
What is the best structure for this task? How to link tables of phones and contacts?
Found a similar question How to store phones in the database?
Is there a separate table with phone numbers for people, a separate table with phone numbers for companies? What other options are there? Or is this the best option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-02-28
@tsklab

Questions about the physical model:
According to the physical model, we can offer:

Diagram
5c78298a91816782867472.png
SELECT Company.Name AS CompanyName, 
       Person.Name AS PersonName, 
       PhoneStorage.Description, 
       Phone.Number, 
       Phone.Description AS PhoneDescription
  FROM PhoneStorage 
    INNER JOIN Phone ON PhoneStorage.Phone = Phone.ID 
    LEFT OUTER JOIN Person ON PhoneStorage.Person = Person.ID 
    LEFT OUTER JOIN Company ON PhoneStorage.Company = Company.ID
  ORDER BY Phone.Number, PersonName
5c78bfdd1ea5a524322008.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question