A
A
Alexander2021-10-06 13:10:45
Database design
Alexander, 2021-10-06 13:10:45

Create products with color variants?

Hello, please tell me how to solve a side task in any of the sql databases?
I have a product that has 8 colors, so I'm confused, because it would be wrong to create a separate product for each color, because all the data is duplicated, and only the color (picture) changes and the display of all products will show a lot of identical products with different coloring, but I need to have only one that contains all the colors and each color has its own pk by which it was possible to understand what color is in the ulr or basket.
I would be very grateful for an answer
615d7595996fc146495630.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2021-10-06
@Zoominger

Create an entry "krossovok_abibas_air_max_97" in the "products" table with an id of, say, "1844".
Create records like this in a separate table (say, "colors"):
"krasniy;1844"
"siniy;1844"
"beliy;1844"
In the list of products, display only "krossovok_abibas_air_max_97", and when you fall into the product card, you already pull up the colors there by the ID of this item.
Did you understand the point?

S
Stanislav Makarov, 2021-10-06
@Nipheris

It's all about understanding the subject area.
It turns out that the "product" in your case is not one product, but many products with similar characteristics. You can call "product" what you display on the main page, and "product" - a specific type of product, and it is with the "product" that you conduct pricing, accounting for balances, and so on.
Well, then everything is according to the classics - for example, you can make a composite primary key for a product, of which the product key is a part. It all depends on what kind of DBMS you have and how convenient it is to work with normal keys.
Of course, this is only one of the solutions. And only one of the aspects, because the question will arise - how to store different fields in the description, slightly different in different products? Well, and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question