简体   繁体   English

简单的产品订单数据库

[英]Simple database for product order

I want to make a simple database to order products, like chips/drinks (as full product, without any specific info about product just name and price for unit) 我想建立一个简单的数据库来订购产品,例如薯条/饮料(作为完整产品,没有关于产品的任何特定信息,只是名称和单位价格)

I designed this but I'm not sure if it's good: 我设计了这个,但不确定是否很好:

**Person:**
id
username
name
password
phone
email
street
zip

**order:**
id
person_id
product_id
date
quantity (neccessary?)
status (done or not)

**product:**
id
name
price

relations: [person] 1 --- 1 [order] 1 --- many [product] (I'm not sure about relations and fields) 关系:[人] 1 --- 1 [订单] 1 ---许多[产品](我不确定关系和领域)

It seems that in your way you are going to end up in orders containing a single product (even if you use the quantity) 看来,按照您的方式,您最终将只能获得包含单个产品的订单(即使您使用的是数量)

I would modify the Order table: 我将修改Order表:

**order:**
id
person_id
date
status (done or not)

And I would add a new table: 我将添加一个新表:

**OrderDetails**
id
order_id
product_id
quantity

You may check out for db normalization. 您可以签出数据库规范化。 You should add columns to a table that are directly related to the table. 您应该在表中添加与该表直接相关的列。 For instance date in the order is valid, because it refers to the order it was made. 例如,订单中的日期是有效的,因为它指的是订单的日期。 On the other hand it wouldn't be valid in the person table (unless it was referring to the person join date). 另一方面,它在人员表中无效(除非它是指人员加入日期)。 So, similarly the quantity refers to the product in the order (thus in OrderDetails) not in the Order or the Product. 因此,类似地,数量是指订单中的产品(因此在OrderDetails中)而不是订单或产品中的产品。

您可能需要在订单和产品之间添加一个中间表,因此您可以多次将同一订单添加到不同的产品中

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

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