L
L
lue merg2019-07-24 16:59:18
Database design
lue merg, 2019-07-24 16:59:18

What should be the normalized database schema for products and categories?

I never understood the one-to-many principle, but maybe someone will just explain it with this example.
There are products, each product can belong to different categories, so each category can belong to many products, how would this be implemented according to the many-to-many scheme?
I would implement this in a 1-to-many manner by creating 2 tables, a product table and a table - a key and a category name.
What other options are there and what advantages does it have over my option.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2019-07-24
@luemerg

In fact, you described a many-to-many relationship. It is implemented by creating an intermediate table containing the product ID and category ID.
poducts (id, name, ...)
category (id, name, ...)
products_categories (product_id, category_id)

I
Ivan Shumov, 2019-07-24
@inoise

It depends on what task and what normal form you need to bring it to) otherwise, you know, there are 3 of them popular, there is a less frequently used 4th, and there it’s already close to 5-6)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question