I have an assignment for shopping cart dealing with shirt store, and was confusing with database design in storing shirt attributes such as color, size and stock for each item.
Let's say to store below shirt to db:
Product name: Nike shirt
Available colors: black, white, blue
Size: M, L, XL
Stock: Black - M - 5 pc
White - L - 10 pc
Blue - M - 2 pc
Blue - XL - 3 pc
(and so on...)
Instead of storing above info iteratively in a table like so:
table shirt
id product color size stock
---------------------------------------------
1 Nike Shirt black M 5
2 Nike Shirt white L 10
3 Nike Shirt blue M 2
4 Nike Shirt blue XL 3
....
What is the best way to design table to keep these attribute and product effectively?
I know that could be JOIN multiple table together, but I need advise on these attributes on how to put separately with difference table and fetch the info when people goes to respective page and show them up how many stock are left for the specific size?