V
V
vladimir percov2017-08-15 09:19:06
Database
vladimir percov, 2017-08-15 09:19:06

How to implement a scalable table?

Good day, gentlemen and ladies!
1. There is a company with sold products
2. There is a table of clients
3. There are plans for the boss to sell products that are completely different from those supplied
. New products will need new parameters (attributes) of clients, and also, for reporting, it will be possible to view a list of used by the client.
How can I implement the clients table so that I don't have to add columns endlessly? Or is there nothing wrong with that?
Thank you.
UPD.
Maxim Fedorov : for example, there is a products table with columns
----------------------------------
| products |
----------------------------------
| id | prod_name | price_price |
------------------------------------
| 1 | product 1 | 500 |
| 2 | product 2 | 700 |
| 3 | Product 3 | 1000 |
-----------------------------------
There is a clients table
------------ ---------------------------------
| clients |
----------------------------------------------------
| id | attrib1 | attrib2 | attrib3 | attrib4 |
----------------------------------------
| 1 | testA | testA | testA | testA |
| 2 | testB | testB | testB | testB |
| 3 | testC | testC | testC | testC |
----------------------------------------
When selling a Product 1, clearance requires attrib1 and attrib3 from clients. When selling Product2, clearance requires attrib2 and attrib4 from clients.
When creating a new product (let it be Product 4), a couple more attributes will need to be added to the clients table.
The question is how to organize these attributes without directly adding columns directly to clients.
PS There was an idea to create a table clients_attrib_for_product, and there it enters data in the form
------------------------------------- -----------------
| clients_attrib_for_product |
-------------------------------------------------- ----
| id | prod_id | client_id | att_name | att_value |
-------------------------------------------------- -----
| 1 | 1 | 2 | attrib1 | testA |
| 2 | 2 | 5 | attrib2 | testB |
| 3 | 3 | 3 | attrib3 | testC |
-------------------------------------------------- -----
But I do not know how it is correct.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2017-08-15
@lega

Add json to products, and clients are not needed here at all.

M
Maxim Fedorov, 2017-09-26
@qonand

in the case of using a relational database, you can use the EAV model to store such data, or switch to a NoSQL database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question