浏览器游戏的建模数据库
我正在为学校项目开发一个使用 symfony 开发的浏览器游戏。
在我的架构中,我有一个桌子播放器和一个桌子库存(包含不同的物品),具有一对一的关系。
我不知道如何建立表库存。经过反思,我找到了两种方法来做到这一点:
1.
TABLE inventory
id
id_player
item1
item2
item3
...
但是如果我想在游戏中添加一个项目,我必须在我的表中添加一列,如果有很多项目,我就会有很多列。
2.
TABLE inventory
id
id_player
item
quantity
我觉得这种方式比较好,但是记录数会很快增加,因为我是逐个玩家逐个项目一行。
还有其他更有效的方法吗?如果不是,两者哪个更好?
I work on a browser game developed with symfony for school project.
In my schema I have a table player and a table inventory (which contains different items) with relation one-to-one.
I'm not sure how I can build the table inventory. After reflexion, I have find two ways to do this :
1.
TABLE inventory
id
id_player
item1
item2
item3
...
But if I want add an item in the game, I have to add a column to my table and if there are a lot of items, I will have many columns.
2.
TABLE inventory
id
id_player
item
quantity
I think this way is better, but the number of records will quickly increase because I have one line by player by item.
There are other methods which are more efficient ? If not, which is the better in the both ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第二种方法应该没问题,只要 id_player 上有索引即可。我不会担心它的空间使用情况。如果每行占用 25 个字节,每个玩家有 400 种类型的物品,并且您有 100 万用户,那么这仍然只是 10 GB。
The second approach should be fine, as long as there's an index on id_player. I wouldn't worry about its space usage. If each row takes 25 bytes and each player has 400 types of items and you have 1 million users, that's still just 10 gigs.
要完成上述答案,您可以添加一个包含项目的表格,然后只需将 item 列更改为 id_item。
To complete the above answer, you could add a table with your items, and then just change your item columns to id_item.