T
T
ta42015-05-29 18:00:17
MySQL
ta4, 2015-05-29 18:00:17

How to organize the database structure for store product characteristics?

It is necessary to store the characteristics of goods in the database.
Here are 2 eeac8a4df90f4ed4adabe9f52d660f63.png
tables there are 2 tables.
The first table is a "characteristic", the second is the possible values.
The main problem is that characteristics come in several types. To do this, we added the "type" field to the characteristics table (the type can be 'checkbox', 'radiobutton', 'multiselect', 'text').
For example, if a characteristic is of the checkbox type (for example, "GPS" has the value either true or false), then it is necessary to store true and false for this characteristic in the value table. There are a lot of such characteristics and for each we store true and false in the table of values. How can I avoid this, or is it normal?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2015-05-29
@sim3x

https://dev.mysql.com/doc/refman/5.0/en/enum.html
// enum in 4.x had issues with performance
or
in the model class, specify the correspondence
Do not forget about the ability to denormalize and put each category in its own table with its own fields

A
Artyom Karetnikov, 2015-05-30
@art_karetnikov

Good. What is there to think, this is not chess. Here you have conditionally 1000 product properties. For some goods, only 3 of them are filled. Of course, you don’t need to keep the rest empty.
What you need - and it's very simple, watch your hand:
We take the id of the product, conditionally 1189. We take three id of the product properties, 11, 22, 33. We start a table with the fields:
Id_ProductProperty int
Id_Product int
Id_Property int
And here we carefully put:
1 1189 11
2 1189 22
3 1189 33
Everything. You have a property - it is in this table, which means True. There is no property - it is not in this table.
The table is completely intovaya, you also put indexes, as expected, on join fields - and everything flies.

K
Kirill Penzin, 2015-05-29
@kir_vesp

Yuzay data types, Luke. There are a lot of data types in a muscle. In fact, one table is needed, which lists the values ​​of the product characteristics. At most, you can create additional tables describing the set of characteristics for each category of goods, if the options for the values ​​there are very different.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question