[英](database design,mysql) Is my database design good for basic shopping cart?(I new in database design)
我是数据库设计的新手,我想确保自己做得好。 请查看我的数据库设计的一部分:
我的基本购物车数据库设计:
//table that holds shopping cart items that customer choose(not press checkout and order //them)
**shopping_cart**
{
id (int)
product_id (int) fk
product_quantity (int)
customer_user_id (int) fk
}
//table that holds product order data in time of checkout.(i hold them because supplier //can change after time products attributes value add some attributes or delete and change //the price of product)
**order**
{
id (int)
product_id (int) fk
customer_user_id (int) fk
}
//table that connect order to attribute table for products attributes value in the moment //of checkout
**order_attributes**
{
id (int)
order_id (int) fk
attribute_id (int) fk
}
//main product table
**product**
{
id (int)
sku (int)
product_name (varchar)
supplier_user_id (int) fk
}
//connection table many to many
**product_attributes**
{
id (int)
product_id (int) fk
attribute_id (int) fk
}
//table that holds products attributes (price, weight, color + new attributes that user //will create)
**attribute**
{
id (int)
product_id (int) fk
attribute_name (varchar)
attribute_value(varchar)
}
谢谢
嗯,您可以从设计中删除两个表:order_attributes,product_attributes。 否则,必须从这么多表中进行联接,您的选择查询就会非常慢。 您可以将属性存储为订单和产品表中的列。
对我来说,这是一个糟糕的设计,因为它使用的属性表是EAV表,并且可能导致性能问题。 花一些时间来实际定义您想要的产品属性,实际上大多数产品都具有相似的属性(颜色,尺寸,单位(10个包装,单个项目等)。EAV是最后的选择。
将价格等详细信息存储在orderdetail表中。 如果产品价格后来有所变化,则您不希望价格发生变化。
我的结构是这样的:订单orderid,日期,客户id订单详细信息order_id,Compnay_id,Product_id,零件编号,产品名称,数量,价格,单位,颜色,大小,其他属性订单注释order_id,注释
产品product_id,零件编号,product_name,Company_id,产品价格,颜色,尺寸,单位
最好设置空列(除非您拥有数百个通常不会使用的属性)(当某些产品的属性不相同时)。此外,如果您想要完整的产品规格,请考虑将其放入大型varchar字段中,全文索引就可以了。 这应该比EAV表更好地执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.