How to Create Better Structure Tables

For my site I have tables

Category :: id | name
Product  :: id | name | categoryid

Now each category can have different sizes, for this I also created a table

Size :: id | name | categoryid | price

Now the problem is that each category also has different ingredients that the customer can choose to add to the purchased product. And these ingredients have different prices for different sizes. For this, I also have a table like

Ingredient :: id | name | sizeid | categoryid | price

I am not sure if this structure is really normalized. Can someone please help me optimize this structure and index me this structure?

+3
source share
3 answers

:: id |
:: id | | categoryid
:: id | | :: id | | Category_Size:: id | | ID |
Category_Ingredient:: id | categoryID | ID |

( ). , .

0

.

, , :

Ingredient :: id | name 

Ingredient_Price :: ingredientid | sizeid | price

Ingredient_Category :: ingredientid | categoryid
+1

. PK , , .
FK:

product.categoryId, 
size.categoryId, 
ingredient.categoryId, 
ingredient.sizeId

, , .

0
source

Source: https://habr.com/ru/post/1782418/


All Articles