Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

php - Mysql Database design structure

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...