数据库
首页 > 数据库> > 我的MySQL设计是否违反了数据库规则?

我的MySQL设计是否违反了数据库规则?

作者:互联网

如果我在MySQL数据库中做正确的事,我需要一个建议.我将这个名为inventory的数据库连接到一个java应用程序,它包含一个名为item的表,这里是详细信息:

> id – int(11),AUTO_INCREMENT
> item_name – varchar(50)
> category – varchar(25)
> q_box – int(11)
> unit_price_box – 加倍
> sub_total_box – double
> q_pc – int(11)
> unit_price_pc – 加倍
> sub_total_pc – double
> grand_total – 加倍
> recent_date_purchased – 日期
> last_date_modified – 时间戳

我已经在开发库存应用程序时使用它来存储库存,但我现在要做的是添加一个表来存储客户的订单.

我打算这样做:

表名:订单

其中包括以下内容:

> order_id – int(11),AUTO_INCREMENT
> item_name – varchar(50)
> category – varchar(25)
> q_box – int(11)
> unit_price_box – double //这是每箱的零售/批发价格
> sub_total_box – double
> q_pc – int(11)
> unit_price_pc – double //这是每台电脑的零售/批发价格
> sub_total_pc – double
> grand_total – 加倍
> customer_name – varchar(50)
> last_date_modified – 时间戳

我的问题是:我是否违反任何MySQL规则,因为我使用的是同一个变量?

或者你有什么建议吗?任何建议都将受到高度赞赏..

提前致谢 :)

解决方法:

使用items表以及orders和order_items表可能会更好.

命令

id int(11), AUTO_INCREMENT
customerid int(11)
orderdate datetime
PRIMARY KEY (id)
FOREIGN KEY (customerid) REFERENCES Customers(Id)

ORDER_ITEMS

orderid int(11),
itemid int(11)
FOREIGN KEY (orderid) REFERENCES Orders(id)
FOREIGN KEY (itemid) REFERENCES Items(Id)

这样就可以减少重复数据.

标签:mysql-management,mysql
来源: https://codeday.me/bug/20190903/1796307.html