(数据库设计,mysql)我的数据库设计对基本购物车有好处吗?(我是数据库设计的新人)

时间:2022-01-28 12:46:05

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

谢谢你

2 个解决方案

#1


1  

For my money, it is a poor design becasue it uses attribute tables whe are EAV tables and which can cause performance problems. 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.

在我看来,这是一个糟糕的设计,因为它使用的属性表是EAV表,会导致性能问题。花点时间来定义你想要的产品属性,对于大多数产品(颜色、尺寸、单位(10包、单品等)来说,几乎都是简单的。EAV是最后的选择。

Store the details of the prices, etc, in the orderdetail table. You do not want the price to change if the product price changes later on down the road.

在orderdetail表中存储价格的详细信息。如果以后的产品价格变动,你不希望价格改变。

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

我的结构应该是这样的:Order orderid, date, customerid订单细节order_id,Compnay_id,Product_id, part_number,product_name, quantity, price, Unit, Color, size,以及其他属性order_id,注意

Products product_id,Part_number, product_name, Company_id, product price, color, size, Unit

产品product_id、Part_number、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. This should perform way better than an EAV table.

最好有空列(除非您有数百个属性,而通常您不会有这些属性),如果某些产品没有相同的attrubutes),如果您想要一个产品的完整规格,可以考虑将它们放入一个大型varchar文件中,并在其中放置一个完整的文本索引。这应该比EAV表更好。

#2


2  

Hmm there are two tables that you can remove from your design: 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.

嗯,您可以从设计中删除两个表:order_attributes, product_attributes。否则,您的select查询将非常缓慢,必须从如此多的表中进行连接。您可以将属性存储为order和product表中的列。

#1


1  

For my money, it is a poor design becasue it uses attribute tables whe are EAV tables and which can cause performance problems. 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.

在我看来,这是一个糟糕的设计,因为它使用的属性表是EAV表,会导致性能问题。花点时间来定义你想要的产品属性,对于大多数产品(颜色、尺寸、单位(10包、单品等)来说,几乎都是简单的。EAV是最后的选择。

Store the details of the prices, etc, in the orderdetail table. You do not want the price to change if the product price changes later on down the road.

在orderdetail表中存储价格的详细信息。如果以后的产品价格变动,你不希望价格改变。

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

我的结构应该是这样的:Order orderid, date, customerid订单细节order_id,Compnay_id,Product_id, part_number,product_name, quantity, price, Unit, Color, size,以及其他属性order_id,注意

Products product_id,Part_number, product_name, Company_id, product price, color, size, Unit

产品product_id、Part_number、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. This should perform way better than an EAV table.

最好有空列(除非您有数百个属性,而通常您不会有这些属性),如果某些产品没有相同的attrubutes),如果您想要一个产品的完整规格,可以考虑将它们放入一个大型varchar文件中,并在其中放置一个完整的文本索引。这应该比EAV表更好。

#2


2  

Hmm there are two tables that you can remove from your design: 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.

嗯,您可以从设计中删除两个表:order_attributes, product_attributes。否则,您的select查询将非常缓慢,必须从如此多的表中进行连接。您可以将属性存储为order和product表中的列。