简体   繁体   中英

Whats the best way to store different prices for one entity in SQL?

So I am building a webpage that shows a bunch of video games located in a SQL database and one suggestion I had was to have the different prices from each region display based on a drop down. My question is trying to figure out whats the best way to store int in the database. Would it be like:

  • GAME
    • CountryID
    • price1
    • CountryID
    • price2
    • CountryID
    • price3 ...

Or is there a better way to do this?

Just a heads up I've only been developing web applications for a year or so and I'm still pretty new to SQL.

Thanks for your input!

I would use multiple tables, one for games and one for region pricing.

Games

+--------+----------+
| GameID | GameName |
+--------+----------+
|      1 | Game1    |
|      2 | Game2    |
|      3 | Game3    |
|      4 | Game4    |
+--------+----------+

RegionPricing

+----------+--------+-------+
| RegionID | GameID | Price |
+----------+--------+-------+
|        1 |      1 |    60 |
|        1 |      2 |    55 |
|        1 |      3 |    45 |
|        1 |      4 |    80 |
|        2 |      1 |    50 |
|        3 |      2 |    30 |
|        3 |      3 |    25 |
|        3 |      4 |    45 |
|        4 |      1 |    60 |
|        4 |      2 |    55 |
|        4 |      3 |    45 |
|        4 |      4 |    80 |
+----------+--------+-------+

By using separate tables you minimize duplicate data and allow for easy granular changes. You may also consider adding a column to RegionPricing for currency. This would also need a Region table, with RegionID and RegionName.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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