MYSQL数据库设计:如何为每个用户存储三维数据?

时间:2022-01-30 12:41:50

To explain my issue I will use an illustration. Say I am a shop owner and I have my 'shop' MYSql database. I then have a table for all the customers of my shop and a table containing all the products I sell.

为了解释我的问题,我将用一个例子来说明。假设我是一个店主,我有我的“商店”MYSql数据库。然后我有一张本店所有顾客的桌子和一张包含我销售的所有产品的桌子。

Along with saving the basic details of the customers (name, email etc) I also want to be able to save each individual basket they create. I can confidently use MYSql tables with 1D data, e.g. one row representing one user / product. How, though, can I store a variable amount of baskets, each containing a variable amount of products - for each user - in this shop database in an efficient way?

除了保存客户的基本细节(姓名、电子邮件等)之外,我还希望能够保存他们创建的每个单独的购物篮。我可以自信地使用具有1D数据的MYSql表,例如一行表示一个用户/产品。但是,我如何能够有效地在这个商店数据库中存储数量可变的购物篮,每个购物篮都包含不同数量的产品(针对每个用户)?

Any suggestions are appreciated, I am fairly new to MYSQL / Database design!

感谢您的建议,我对MYSQL /数据库设计比较陌生!

Thanks, Steve.

谢谢你,史蒂夫。

1 个解决方案

#1


2  

A fully normalized design would have a basket table that has its own unique id and references the customer id. This basket table could also have information about the basket, such as when it was created, if it was canceled or taken through to payment, etc. Your DB would then also have a basket_products table that references the basket table's unique id, and the product's id, along with any information that you would have for that product when it was put in that basket. This would allow for say temporary discounts, or special customer deals on that product at that time.

完全规范化的设计会有一篮子表有自己的独特的id和客户id引用。这个篮子表也可以篮子的信息,如建立之时,如果被取消或者采取通过付款,等等。你的数据库也将一篮子basket_products表引用表的唯一id,和产品的id,以及任何你会的信息,产品的时候放在篮子里。这将允许暂时的折扣,或当时的特殊客户交易。

BASKET
id  autonum
customer_id  references customer.id
other info about the basket

BASKET_PRODUCTS (or PRODUCTS_IN_BASKET)
basket_id  references basket.id
product_id  references product.id
other info about the products as the are put in this basket (number purchased, price per, etc)

#1


2  

A fully normalized design would have a basket table that has its own unique id and references the customer id. This basket table could also have information about the basket, such as when it was created, if it was canceled or taken through to payment, etc. Your DB would then also have a basket_products table that references the basket table's unique id, and the product's id, along with any information that you would have for that product when it was put in that basket. This would allow for say temporary discounts, or special customer deals on that product at that time.

完全规范化的设计会有一篮子表有自己的独特的id和客户id引用。这个篮子表也可以篮子的信息,如建立之时,如果被取消或者采取通过付款,等等。你的数据库也将一篮子basket_products表引用表的唯一id,和产品的id,以及任何你会的信息,产品的时候放在篮子里。这将允许暂时的折扣,或当时的特殊客户交易。

BASKET
id  autonum
customer_id  references customer.id
other info about the basket

BASKET_PRODUCTS (or PRODUCTS_IN_BASKET)
basket_id  references basket.id
product_id  references product.id
other info about the products as the are put in this basket (number purchased, price per, etc)