MySQL-保存和加载项目的最佳方法 [英] MySQL - Best method of saving and loading items
问题描述
因此,在我的较老作品中,我一直使用文本"数据类型来存储项目,就像这样:
So on my older work, I had always used the 'text' data type to store items, like so:
0=4151:54;1=995:5000;2=521:1;
所以基本上是:slot=item:amount;
我一直在寻找在sql数据库中存储信息的最佳方法,无论我走到哪里,它都说使用文本会大大提高性能.
I've been looking into finding the best ways of storing information in a sql database, and everywhere i go, it says that using text is a big performance hit.
我正在考虑做其他事情,例如创建一个包含以下各列的表:
I was thinking of doing something else, like having a table with the following columns:
id, owner_id, slot_id, item_id, amount
我现在可以在其中为字符分配的每个项目插入一行.但是我不知道如何保存它们,因为插槽的项目可以更改,等等.一个角色有28个库存插槽和500个银行插槽,我应该在注册时全部插入吗?还是有一种更聪明的方式保存项目
Where as now i can just insert a row for each item a character allocates. But i have no clue how to save them, since the slot's item can change, etc. A character has 28 inventory slots, and 500 bank slots, should i insert them all at registration? or is there a smarter way to save the items
推荐答案
是的,使用该结构.使用文本存储关系数据无法达到关系数据库的目的.
Yes use that structure. Using text to store relational data defeats the purpose of a relational database.
我看不到您在注册时全部插入的意思.不能按需要插入它们吗?
I don't see what you mean by insert them all at registration. Can you not insert them as you need to?
修改
根据您之前的评论,我建议仅在需要时插入插槽(如果我理解您的问题).如果需要,可以在应用程序中保留插槽的ID.
Based on your previous comment I would recommend only inserting a slot as it is needed (if I understand your problem). It may be an idea to keep the ID of the slot in the application, if need be.
这篇关于MySQL-保存和加载项目的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!