Mysql数据库设计结构 [英] Mysql Database design structure

查看:94
本文介绍了Mysql数据库设计结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在插入记录时,哪个是更好的数据库设计?

Which is a better db design when inserting records?

**Option 1.**
uid|itemid| qty | price | amount
1  |13| 2  |  100    |200

**Option 2.**
uid| itemid| qty | price | amount
1  |13| 1 | 100 | 100
2  |13| 1 | 100 | 100

在选项2中,然后通过mysql查询检索行并使用id ...

In option 2 then retrieve rows via mysql query and calculate using id ...

推荐答案

似乎你想保留每个订单的原价。我要做的是使用选项1,然后在表中创建另一个列,其中包含标识顺序中每个项目的字符串。

It seems like you want to retain the original price of each item ordered. What I'd do is go with option 1, then create another column in your table that holds a string that identifies each item in the order.

例如,如果我出售水果,香蕉可以有 iZ 作为唯一键。一个苹果可以有 6U 作为唯一键。当用户下订单时,这些唯一键将插入到新列中。因此,当您看到此列的数据是 iZ6U 时,您会知道用户订购了一个苹果和一个香蕉。

For example, if I were selling fruit, a banana could have iZ as a unique key. And an apple could have 6U as a unique key. When a user places an order, these unique keys would be inserted into your new column. So when you see this column's data is iZ6U you'd know that the user ordered an apple and a banana.

这篇关于Mysql数据库设计结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆