简体   繁体   English

(数据库设计,mysql)我的数据库设计适合基本的购物车吗?(我是数据库设计的新手)

[英](database design,mysql) Is my database design good for basic shopping cart?(I new in database design)

I new in database design, I want to be sure that i make it well. 我是数据库设计的新手,我想确保自己做得好。 Please take a look for part of my database design: 请查看我的数据库设计的一部分:

My database design for basic shopping cart: 我的基本购物车数据库设计:

//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)
}

Thanks you 谢谢

Hmm there are two tables that you can remove from your design: order_attributes, product_attributes. 嗯,您可以从设计中删除两个表:order_attributes,product_attributes。 Otherwise, your select query would be very slow having to join from so many tables. 否则,必须从这么多表中进行联接,您的选择查询就会非常慢。 You can store the attributes as columns in the order and product table. 您可以将属性存储为订单和产品表中的列。

For my money, it is a poor design becasue it uses attribute tables whe are EAV tables and which can cause performance problems. 对我来说,这是一个糟糕的设计,因为它使用的属性表是EAV表,并且可能导致性能问题。 Take the time to actually define the attributes you want to have for the products, there really are mostly simliar for most products (color, size, units(package of 10, single item, etc.). EAV is the last resort. 花一些时间来实际定义您想要的产品属性,实际上大多数产品都具有相似的属性(颜色,尺寸,单位(10个包装,单个项目等)。EAV是最后的选择。

Store the details of the prices, etc, in the orderdetail table. 将价格等详细信息存储在orderdetail表中。 You do not want the price to change if the product price changes later on down the road. 如果产品价格后来有所变化,则您不希望价格发生变化。

My structure would be somthing like: Order orderid, date, customerid Order details order_id,Compnay_id,Product_id, part_number,product_name, quantity, price, Unit, Color, size, other attributes Order notes order_id, note 我的结构是这样的:订单orderid,日期,客户id订单详细信息order_id,Compnay_id,Product_id,零件编号,产品名称,数量,价格,单位,颜色,大小,其他属性订单注释order_id,注释

Products product_id,Part_number, product_name, Company_id, product price, color, size, Unit 产品product_id,零件编号,product_name,Company_id,产品价格,颜色,尺寸,单位

Better to have null columns (unless you have hundreds of attributes which you won't generally) when some products don't have the same attrubutes) Further if you want complete specs for a product, consider puttingthem in a large varchar filed and putting a full text index on it. 最好设置空列(除非您拥有数百个通常不会使用的属性)(当某些产品的属性不相同时)。此外,如果您想要完整的产品规格,请考虑将其放入大型varchar字段中,全文索引就可以了。 This should perform way better than an EAV table. 这应该比EAV表更好地执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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