T
T
Timur Khudiyev2018-04-24 12:48:55
MySQL
Timur Khudiyev, 2018-04-24 12:48:55

How to properly organize the storage of products for the bulletin board?

Good day. There is a task to make a bulletin board.
There are categories:

  1. Auto
  2. Apartments
  3. Phones
  4. Etc...

The bottom line is that products can have their own characteristics. For example, apartments have space, but telephones do not. Or, let's say, a car has the property engine size, body type.
How to properly organize the storage of products and categories in the database?
It seems to me that it would be wrong to make columns for all available properties in the product table and fill them in depending on the categories. This will cause inconvenience at the first new category if it has its own properties.
If anyone has any ideas please point me in the right direction.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton, 2018-04-24
@Eridani

There are categories, there is a table with all characteristics, where each characteristic has a parent category ID.

T
ThunderCat, 2018-04-24
@ThunderCat

Implementation options are simply innumerable, they all have their pros and cons, depending on what and with what you will combine. Of course, the worst option is one table with all the properties, you need to look towards solutions with maximum normalization (see the material on normal forms of the database), and having created a schema with a normal form, denormalize in the right places necessary for any special functionality .
Simply put - (almost) all ad properties should be stored separately from the ad entries, and linked through an intermediate table by keys. the same applies to user properties.

L
Lander, 2018-04-24
@usdglander

1. Create a table with common fields for the product. + field type
2. For each type of product, create a table with fields ONLY for this type of product.
3. Depending on the value of the type field, you do a JOIN of one or another table in the query.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question