How to handle multiple user save games of a RPG in SQL
I have a complex RPG video game under development and it supports multiplayers, matchmaking, and cloud save game. For a lot of reasons, we are handling the "cloud save" ourselves - mainly for cross platform support.
For this, we created a SQL database on our servers, and for now we have a "users" table handling the different login, password, save, Steam/PlayStation/etc ID, and anything unique to a user. We have a "saves" table, and that's where I feel we can improve. The table definition looks like this:
CREATE TABLE saves (
id uniqueidentifier PRIMARY KEY,
user_id INT NOT NULL,
create_date DATETIME NOT NULL,
edit_date DATETIME NOT NULL,
name text NOT NULL,
data text NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
The place I feel is lacking the data text NOT NULL, where right now we simply feed a Json'ed of a save game. In a RPG, a player may have an inventory, a number of quests, different NPC dialog states and so on. However, from what I understand there is no "clean" way of doing arrays inside a table cell in SQL. Having each saves game being in a different table would be terrible, as we could end up with tens or hundreds of tables.
Is there something we are overlooking, or is using a cell to store a serialized version of the save data the best I can do in SQL?
sql arrays json
|
show 3 more comments
I have a complex RPG video game under development and it supports multiplayers, matchmaking, and cloud save game. For a lot of reasons, we are handling the "cloud save" ourselves - mainly for cross platform support.
For this, we created a SQL database on our servers, and for now we have a "users" table handling the different login, password, save, Steam/PlayStation/etc ID, and anything unique to a user. We have a "saves" table, and that's where I feel we can improve. The table definition looks like this:
CREATE TABLE saves (
id uniqueidentifier PRIMARY KEY,
user_id INT NOT NULL,
create_date DATETIME NOT NULL,
edit_date DATETIME NOT NULL,
name text NOT NULL,
data text NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
The place I feel is lacking the data text NOT NULL, where right now we simply feed a Json'ed of a save game. In a RPG, a player may have an inventory, a number of quests, different NPC dialog states and so on. However, from what I understand there is no "clean" way of doing arrays inside a table cell in SQL. Having each saves game being in a different table would be terrible, as we could end up with tens or hundreds of tables.
Is there something we are overlooking, or is using a cell to store a serialized version of the save data the best I can do in SQL?
sql arrays json
You have the option of storting json data into your database. Otherwise almost all of the database have support for storing xml.
– George Joseph
Nov 20 '18 at 5:32
@GeorgeJoseph : I know, that's what I said I was doing. Is there a way to store Json other than by a "text" data type? But my goal was to not just dumb a huge string and go "That's the data" and be more "This cell holds the inventory, this cell holds the stats, this cell holds the quests". I assume this is impossible?
– LightStriker
Nov 20 '18 at 5:36
It is possible to create user defined type and store it in the database table. The user defined type would contain the attributes. See an example in oracle database : oracle-base.com/articles/misc/object-views-and-nested-tables
– George Joseph
Nov 20 '18 at 5:45
You could use either XML or JSON and build SQL views to give you an easy query mechanism. In a way expand the json into relational view. It might not be the most performant. blogs.msdn.microsoft.com/sqlserverstorageengine/2015/12/09/….
– Akrion
Nov 20 '18 at 5:46
@Akrion That's just for views, no? I still need to store the data as a string?
– LightStriker
Nov 20 '18 at 5:54
|
show 3 more comments
I have a complex RPG video game under development and it supports multiplayers, matchmaking, and cloud save game. For a lot of reasons, we are handling the "cloud save" ourselves - mainly for cross platform support.
For this, we created a SQL database on our servers, and for now we have a "users" table handling the different login, password, save, Steam/PlayStation/etc ID, and anything unique to a user. We have a "saves" table, and that's where I feel we can improve. The table definition looks like this:
CREATE TABLE saves (
id uniqueidentifier PRIMARY KEY,
user_id INT NOT NULL,
create_date DATETIME NOT NULL,
edit_date DATETIME NOT NULL,
name text NOT NULL,
data text NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
The place I feel is lacking the data text NOT NULL, where right now we simply feed a Json'ed of a save game. In a RPG, a player may have an inventory, a number of quests, different NPC dialog states and so on. However, from what I understand there is no "clean" way of doing arrays inside a table cell in SQL. Having each saves game being in a different table would be terrible, as we could end up with tens or hundreds of tables.
Is there something we are overlooking, or is using a cell to store a serialized version of the save data the best I can do in SQL?
sql arrays json
I have a complex RPG video game under development and it supports multiplayers, matchmaking, and cloud save game. For a lot of reasons, we are handling the "cloud save" ourselves - mainly for cross platform support.
For this, we created a SQL database on our servers, and for now we have a "users" table handling the different login, password, save, Steam/PlayStation/etc ID, and anything unique to a user. We have a "saves" table, and that's where I feel we can improve. The table definition looks like this:
CREATE TABLE saves (
id uniqueidentifier PRIMARY KEY,
user_id INT NOT NULL,
create_date DATETIME NOT NULL,
edit_date DATETIME NOT NULL,
name text NOT NULL,
data text NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
The place I feel is lacking the data text NOT NULL, where right now we simply feed a Json'ed of a save game. In a RPG, a player may have an inventory, a number of quests, different NPC dialog states and so on. However, from what I understand there is no "clean" way of doing arrays inside a table cell in SQL. Having each saves game being in a different table would be terrible, as we could end up with tens or hundreds of tables.
Is there something we are overlooking, or is using a cell to store a serialized version of the save data the best I can do in SQL?
sql arrays json
sql arrays json
asked Nov 20 '18 at 5:29
LightStrikerLightStriker
12.7k21724
12.7k21724
You have the option of storting json data into your database. Otherwise almost all of the database have support for storing xml.
– George Joseph
Nov 20 '18 at 5:32
@GeorgeJoseph : I know, that's what I said I was doing. Is there a way to store Json other than by a "text" data type? But my goal was to not just dumb a huge string and go "That's the data" and be more "This cell holds the inventory, this cell holds the stats, this cell holds the quests". I assume this is impossible?
– LightStriker
Nov 20 '18 at 5:36
It is possible to create user defined type and store it in the database table. The user defined type would contain the attributes. See an example in oracle database : oracle-base.com/articles/misc/object-views-and-nested-tables
– George Joseph
Nov 20 '18 at 5:45
You could use either XML or JSON and build SQL views to give you an easy query mechanism. In a way expand the json into relational view. It might not be the most performant. blogs.msdn.microsoft.com/sqlserverstorageengine/2015/12/09/….
– Akrion
Nov 20 '18 at 5:46
@Akrion That's just for views, no? I still need to store the data as a string?
– LightStriker
Nov 20 '18 at 5:54
|
show 3 more comments
You have the option of storting json data into your database. Otherwise almost all of the database have support for storing xml.
– George Joseph
Nov 20 '18 at 5:32
@GeorgeJoseph : I know, that's what I said I was doing. Is there a way to store Json other than by a "text" data type? But my goal was to not just dumb a huge string and go "That's the data" and be more "This cell holds the inventory, this cell holds the stats, this cell holds the quests". I assume this is impossible?
– LightStriker
Nov 20 '18 at 5:36
It is possible to create user defined type and store it in the database table. The user defined type would contain the attributes. See an example in oracle database : oracle-base.com/articles/misc/object-views-and-nested-tables
– George Joseph
Nov 20 '18 at 5:45
You could use either XML or JSON and build SQL views to give you an easy query mechanism. In a way expand the json into relational view. It might not be the most performant. blogs.msdn.microsoft.com/sqlserverstorageengine/2015/12/09/….
– Akrion
Nov 20 '18 at 5:46
@Akrion That's just for views, no? I still need to store the data as a string?
– LightStriker
Nov 20 '18 at 5:54
You have the option of storting json data into your database. Otherwise almost all of the database have support for storing xml.
– George Joseph
Nov 20 '18 at 5:32
You have the option of storting json data into your database. Otherwise almost all of the database have support for storing xml.
– George Joseph
Nov 20 '18 at 5:32
@GeorgeJoseph : I know, that's what I said I was doing. Is there a way to store Json other than by a "text" data type? But my goal was to not just dumb a huge string and go "That's the data" and be more "This cell holds the inventory, this cell holds the stats, this cell holds the quests". I assume this is impossible?
– LightStriker
Nov 20 '18 at 5:36
@GeorgeJoseph : I know, that's what I said I was doing. Is there a way to store Json other than by a "text" data type? But my goal was to not just dumb a huge string and go "That's the data" and be more "This cell holds the inventory, this cell holds the stats, this cell holds the quests". I assume this is impossible?
– LightStriker
Nov 20 '18 at 5:36
It is possible to create user defined type and store it in the database table. The user defined type would contain the attributes. See an example in oracle database : oracle-base.com/articles/misc/object-views-and-nested-tables
– George Joseph
Nov 20 '18 at 5:45
It is possible to create user defined type and store it in the database table. The user defined type would contain the attributes. See an example in oracle database : oracle-base.com/articles/misc/object-views-and-nested-tables
– George Joseph
Nov 20 '18 at 5:45
You could use either XML or JSON and build SQL views to give you an easy query mechanism. In a way expand the json into relational view. It might not be the most performant. blogs.msdn.microsoft.com/sqlserverstorageengine/2015/12/09/….
– Akrion
Nov 20 '18 at 5:46
You could use either XML or JSON and build SQL views to give you an easy query mechanism. In a way expand the json into relational view. It might not be the most performant. blogs.msdn.microsoft.com/sqlserverstorageengine/2015/12/09/….
– Akrion
Nov 20 '18 at 5:46
@Akrion That's just for views, no? I still need to store the data as a string?
– LightStriker
Nov 20 '18 at 5:54
@Akrion That's just for views, no? I still need to store the data as a string?
– LightStriker
Nov 20 '18 at 5:54
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386770%2fhow-to-handle-multiple-user-save-games-of-a-rpg-in-sql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386770%2fhow-to-handle-multiple-user-save-games-of-a-rpg-in-sql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You have the option of storting json data into your database. Otherwise almost all of the database have support for storing xml.
– George Joseph
Nov 20 '18 at 5:32
@GeorgeJoseph : I know, that's what I said I was doing. Is there a way to store Json other than by a "text" data type? But my goal was to not just dumb a huge string and go "That's the data" and be more "This cell holds the inventory, this cell holds the stats, this cell holds the quests". I assume this is impossible?
– LightStriker
Nov 20 '18 at 5:36
It is possible to create user defined type and store it in the database table. The user defined type would contain the attributes. See an example in oracle database : oracle-base.com/articles/misc/object-views-and-nested-tables
– George Joseph
Nov 20 '18 at 5:45
You could use either XML or JSON and build SQL views to give you an easy query mechanism. In a way expand the json into relational view. It might not be the most performant. blogs.msdn.microsoft.com/sqlserverstorageengine/2015/12/09/….
– Akrion
Nov 20 '18 at 5:46
@Akrion That's just for views, no? I still need to store the data as a string?
– LightStriker
Nov 20 '18 at 5:54