L
L
l4m3r2018-09-23 14:06:56
Database design
l4m3r, 2018-09-23 14:06:56

Is denormalization necessary?

Let's say we have a customer table:

clients
  id
  first_name
  last_name
  middle_name
  phone
  email
  passport_series
  passport_number
  passport_issued_on
  passport_issued_by
  place_of_residence
  drivers_license_number
  comment
  status

Is it really necessary to duplicate all fields (id, client_id, client_first_name, client_last_name, ...) in the orders table (id, client_id, ...)? On the one hand, this way the order is fixed permanently, even if the client is deleted or his data is changed. But on the other hand, it is a nightmarish redundancy, because there may be other 1 to 1 relationships in the orders table, and as a result there will be a million fields. Or can it make a summing field like orders(id, client_id
, client_info (Ivanov I. pass. 0301 333333, phone 8999999999)?
what to restore the record.What is the
right thing to do?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan Shumov, 2018-09-23
@l4m3r

The answer is from a person who has been working with a similar system for 5 years and who has already realized himself.
You are only partly right. You have two entities - order and customer. Depending on your industry, there is an order initiator, the name under which the order was placed, and a way to contact the order.
What is the name and how to contact the one who called you, you can never really guarantee. In addition, the client may have several phone numbers and mails.
I can advise you in case of a clear match of the client and bind him through client_id and duplicate his full name in client_title (for example), as well as the expected contact for communication.
If you keep only the client base, you will quickly run into the fact that people often change phones and then it will become impossible to get through to the client. You will kill yourself to support this information (you are not the FSB, well)

L
LamerToExpert1, 2018-09-23
@LamerToExpert1

TAB - orders (id, client_id, .... ) what's the problem with just leaving it like this, why rewrite the data in orders as well?

S
sim3x, 2018-09-23
@sim3x

0. Ask the customer
1. There will be redundancy on millions of records
2. Json selections are quite fast now

A
Andrey Skorzhinsky, 2018-09-23
@AndyKorg

But a friend solved a similar problem5a9254c4a0730725193489.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question