Search code examples
phpdatabasedatabase-designinventory

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.


Solution

  • 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.