A
A
amazinginternetsites2014-06-23 16:36:44
PHP
amazinginternetsites, 2014-06-23 16:36:44

Optimal database structure. How to organize correctly?

Friends. Now the data of each user is written to the database in the standard way:
id info skype adress - and so on.
The site is narrowly thematic, so it is necessary that each user can fill out his own price list. Rather, simply indicate the prices for the list proposed in advance
. Here is the question. I suppose you need to create a new table like:
id (user) item_name1 (product name) item_price1 (price) item_name2 (product name) item_price2 (price)
The difficulty is that there are more than 200 elements (item_name). You will have to inflate the table or you can make it more optimal ?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pi314, 2014-06-23
@amazinginternetsites

There is no such thing as an optimal data structure at all. In this case, you can, for example, create two additional. tables:

item_name (id, name);
item_user_price(id_user, id_item, price);

The first will have "more than 200" entries (which, by the way, can be deleted / added over time), the second - as many as prices will be entered by users (I doubt that users will be happy to enter all 200 prices at a time; or maybe someone In general, there are not all prices).
Such a structure will give minimal redundancy. But whether it will be "optimal" in terms of speed and memory consumption depends on the specific requests that will be executed on it.

O
Oleg Krasnov, 2014-06-23
@OKrasnov

Separate table of users.
Separate table of products.
A third table that combines user id, product id, plus price.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question