简体   繁体   中英

Database design for products with multiple (flexible) variables

There are alot of questions for my "problem" or "challenge". But none of them really fit my needs. Okay, here I go:

I want a database which holds variable attributes. Now I "hardcoded" them into the database (see image) as a columnname. See "color" and "size". But what if I want a new attribute? For example "model". I need to adjust the database and add a column. I don't want this.

在此处输入图片说明

Do you have any ideas? I'm thinking for a solution the past few months, and nothing good so far...

So, after all the comments, this is what it now looks like. First the products table:

table: products
column: id
column: name
column: categoryId

Then the table with the stocked items. Each variation of a product should be respresented here:

table: items
column: id
column: productId
column: stock
column: price

Finally the table that contains the attributes of the stocked items:

tablet: attributes
column: id
column: itemId
column: type <color,size>
column: value <yellow,brown,large,small>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM