订单上产品属性的数据库结构

时间:2014-03-20 08:34:55

标签: mysql database-design

由于产品属性,我正在制作POS并且目前仍然停留在订单处理上。

截至目前,数据库看起来像这样:

tbl_products

tbl_attributes (attr id, name, extra price)

tbl_sales ( where i store the time, total price etc)

tbl_salelines ( where i store what items have being order for a certain sale).

问题是存储商品订单的属性。 一个项目没有固定数量的属性。它可以从1到10-15 因此我不认为在attr_1 attr_2等tbl_salelines中创建一些列会解决这个问题。

我该如何处理?

1 个答案:

答案 0 :(得分:0)

您不能在tbl_attributes中使用外键来表示tbl_salelines表。因此,您可以拥有1个销售线,并且对于该销售线,您可以添加与销售线有关的多个属性?

示例:

tbl_saleline 1

Id -> 1    

tbl_attributes

**Attribute 1**
Id -> 1
name -> 'attribute 1'
**SaleLine_Id  -> 1 (FK->tbl_saleline)**

**Attribute 2**
Id -> 2
name -> 'attribute 2'
**SaleLine_Id -> 1  (FK->tbl_saleline)**