Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inventory design database with colors and sizes

I'm planning on making a inventory database design to keep track of what we have in our shop. I'm thinking of storing an array in the database with all sizes and colors like:

array('S-groen' => 6,'M-groen' => 0,'L-groen' => 2,'S-zwart' => 9,'M-zwart' => 0,'L-zwart' => 3);

Where S is the size, and groen is the color.

But is it good practice to do it like this, or is there a better way?

So my database will be: ID - product_id - aantal. In aantal will be the array.

like image 303
Refilon Avatar asked Dec 05 '25 13:12

Refilon


1 Answers

Don't store multiple values in one column in a relational database - it's generally considered bad practice.

It would be better to have two tables, one with a product name and product ID, and another for variations (having columns variation_id, product_id, size, colour, quantity). The product_id column in the variation table will be a foreign key to the product table.

like image 95
stwalkerster Avatar answered Dec 07 '25 02:12

stwalkerster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!