Is this the best way to store this data?What is the ideal data type to use when storing latitude / longitude in a MySQL database?Improve INSERT-per-second performance of SQLite?What are the best practices for SQLite on Android?How to Store Historical DataWhat are the options for storing hierarchical data in a relational database?Supertype/subtype db design with subtype cross-linkDatabase Historical DataWhat's the best way to store an array in a relational database?What is the correct database structure to store historical data?What is the best design for table of parameters?
Anagram holiday
What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?
Withdrawals from HSA
Do I have a twin with permutated remainders?
Stopping power of mountain vs road bike
Can I ask the recruiters in my resume to put the reason why I am rejected?
Why is the 'in' operator throwing an error with a string literal instead of logging false?
Can one be a co-translator of a book, if he does not know the language that the book is translated into?
I Accidentally Deleted a Stock Terminal Theme
How can saying a song's name be a copyright violation?
Why is the ratio of two extensive quantities always intensive?
How do I write bicross product symbols in latex?
Assassin's bullet with mercury
Why doesn't H₄O²⁺ exist?
Is the Joker left-handed?
How to draw the figure with four pentagons?
What to put in ESTA if staying in US for a few days before going on to Canada
What is going on with Captain Marvel's blood colour?
What killed these X2 caps?
Why can't we play rap on piano?
In Romance of the Three Kingdoms why do people still use bamboo sticks when papers are already invented?
Brothers & sisters
Were any external disk drives stacked vertically?
Is "remove commented out code" correct English?
Is this the best way to store this data?
What is the ideal data type to use when storing latitude / longitude in a MySQL database?Improve INSERT-per-second performance of SQLite?What are the best practices for SQLite on Android?How to Store Historical DataWhat are the options for storing hierarchical data in a relational database?Supertype/subtype db design with subtype cross-linkDatabase Historical DataWhat's the best way to store an array in a relational database?What is the correct database structure to store historical data?What is the best design for table of parameters?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
will start by saying I am new to database design but intend to move across to SQLite for one of my projects with python to make reading data more efficient. Currently, I have a tree-like structure of my data stored for a game which gets recorded hourly. I have a tree of folders in the following format: Username/Year/Month/date/time.csv
My aim to scrap that completely and after some discussion over on reddit came up with some basic design but still not sure if it is the best. I will post the ER diagram I have drawn here:

So some clarification on each of these:
- server gives the server the user was logged into (at the time of the recording)
- UserExperience will record all seen skills in which experience was gained in over the hour (and how much experience). So an aggregate for the hour
- This is one i'm really unsure on - UserActivites. This could be variable text of some events that may have happened over the hour ("I levelled X skill to level Y", "I killed Z many of boss A", "I completed quest B") and many more that are added and removed overtime, so not something I can exactly make a primary-key. I'm not really sure what can be done here.
Any help would be really appreciated :D feel free to ask for any clarification. Also not entirely sure how I would do queries to get statistics of some set of users between 2 dates but that is a separate problem
Thanks for any responses!
sqlite database-design relational-database
add a comment |
will start by saying I am new to database design but intend to move across to SQLite for one of my projects with python to make reading data more efficient. Currently, I have a tree-like structure of my data stored for a game which gets recorded hourly. I have a tree of folders in the following format: Username/Year/Month/date/time.csv
My aim to scrap that completely and after some discussion over on reddit came up with some basic design but still not sure if it is the best. I will post the ER diagram I have drawn here:

So some clarification on each of these:
- server gives the server the user was logged into (at the time of the recording)
- UserExperience will record all seen skills in which experience was gained in over the hour (and how much experience). So an aggregate for the hour
- This is one i'm really unsure on - UserActivites. This could be variable text of some events that may have happened over the hour ("I levelled X skill to level Y", "I killed Z many of boss A", "I completed quest B") and many more that are added and removed overtime, so not something I can exactly make a primary-key. I'm not really sure what can be done here.
Any help would be really appreciated :D feel free to ask for any clarification. Also not entirely sure how I would do queries to get statistics of some set of users between 2 dates but that is a separate problem
Thanks for any responses!
sqlite database-design relational-database
add a comment |
will start by saying I am new to database design but intend to move across to SQLite for one of my projects with python to make reading data more efficient. Currently, I have a tree-like structure of my data stored for a game which gets recorded hourly. I have a tree of folders in the following format: Username/Year/Month/date/time.csv
My aim to scrap that completely and after some discussion over on reddit came up with some basic design but still not sure if it is the best. I will post the ER diagram I have drawn here:

So some clarification on each of these:
- server gives the server the user was logged into (at the time of the recording)
- UserExperience will record all seen skills in which experience was gained in over the hour (and how much experience). So an aggregate for the hour
- This is one i'm really unsure on - UserActivites. This could be variable text of some events that may have happened over the hour ("I levelled X skill to level Y", "I killed Z many of boss A", "I completed quest B") and many more that are added and removed overtime, so not something I can exactly make a primary-key. I'm not really sure what can be done here.
Any help would be really appreciated :D feel free to ask for any clarification. Also not entirely sure how I would do queries to get statistics of some set of users between 2 dates but that is a separate problem
Thanks for any responses!
sqlite database-design relational-database
will start by saying I am new to database design but intend to move across to SQLite for one of my projects with python to make reading data more efficient. Currently, I have a tree-like structure of my data stored for a game which gets recorded hourly. I have a tree of folders in the following format: Username/Year/Month/date/time.csv
My aim to scrap that completely and after some discussion over on reddit came up with some basic design but still not sure if it is the best. I will post the ER diagram I have drawn here:

So some clarification on each of these:
- server gives the server the user was logged into (at the time of the recording)
- UserExperience will record all seen skills in which experience was gained in over the hour (and how much experience). So an aggregate for the hour
- This is one i'm really unsure on - UserActivites. This could be variable text of some events that may have happened over the hour ("I levelled X skill to level Y", "I killed Z many of boss A", "I completed quest B") and many more that are added and removed overtime, so not something I can exactly make a primary-key. I'm not really sure what can be done here.
Any help would be really appreciated :D feel free to ask for any clarification. Also not entirely sure how I would do queries to get statistics of some set of users between 2 dates but that is a separate problem
Thanks for any responses!
sqlite database-design relational-database
sqlite database-design relational-database
asked Mar 21 at 21:53
NightShadeNightShade
11410
11410
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
So the activity (in UserActivites) is always one that relates to a (over the time maybe growing) Activities lookup table. The text representation of the activity is in the Activities table and you are just linking to it from your UserActivities table - seems ok so far. You have already a foreign key pointing from UserActivities.ActivityID to Activities.ActivityID (and the same for Username to UserStatus)?
The datetime is just a point in time - no need to put it into some sort of combined index (as the primary key is). You might index the datetime in the future for a better query performance though.
What I would do is:
- throw away the combined primary key on UserActivities
- create a non-meaningful, auto-incrementing integer primary key in the UserActivities table (
ID INTEGER PRIMARY KEY)
Things you should consider:
- create an index on Username and another one on ActivityID in UserActivities; it's not necessary, but recommended that child key columns of foreign keys have an index (https://sqlite.org/foreignkeys.html#fk_indexes)
Your data design looks good that way. You mentioned "and removed overtime" concerning the user activities (if I understood correctly). If so I would create a boolean column in UserActivities for deleted records. That way you can analyze activities that have been removed. I would never delete records once they have been created in the database.
What I meant by removed overtime is that the game may no longer post those activities for the game. I myself would have no need to remove them :) So, if I understand this right, remove the activities table altogether, and the composite-primary key in UserActivities, but place a foreign key pointing to the composite primary key of UserStatus? this sounds like a good model :) would there be any harm in indexing everything here? I also read auto-incrementing keys are not recommended and to use RowID if not deleting any records
– NightShade
Mar 22 at 10:28
No, I would say auto-incrementing keys are recommended (they are the RowID in fact). I'm not sure if I really understand the composite primary key of your UserStatus table... "indexing everything" always comes with a price: every index causes additional load on a database write. So only index if it makes sense and the current model really suffers from a bad performance when you query it.
– Oliver Jakoubek
Mar 25 at 13:25
add a comment |
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%2f55289823%2fis-this-the-best-way-to-store-this-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So the activity (in UserActivites) is always one that relates to a (over the time maybe growing) Activities lookup table. The text representation of the activity is in the Activities table and you are just linking to it from your UserActivities table - seems ok so far. You have already a foreign key pointing from UserActivities.ActivityID to Activities.ActivityID (and the same for Username to UserStatus)?
The datetime is just a point in time - no need to put it into some sort of combined index (as the primary key is). You might index the datetime in the future for a better query performance though.
What I would do is:
- throw away the combined primary key on UserActivities
- create a non-meaningful, auto-incrementing integer primary key in the UserActivities table (
ID INTEGER PRIMARY KEY)
Things you should consider:
- create an index on Username and another one on ActivityID in UserActivities; it's not necessary, but recommended that child key columns of foreign keys have an index (https://sqlite.org/foreignkeys.html#fk_indexes)
Your data design looks good that way. You mentioned "and removed overtime" concerning the user activities (if I understood correctly). If so I would create a boolean column in UserActivities for deleted records. That way you can analyze activities that have been removed. I would never delete records once they have been created in the database.
What I meant by removed overtime is that the game may no longer post those activities for the game. I myself would have no need to remove them :) So, if I understand this right, remove the activities table altogether, and the composite-primary key in UserActivities, but place a foreign key pointing to the composite primary key of UserStatus? this sounds like a good model :) would there be any harm in indexing everything here? I also read auto-incrementing keys are not recommended and to use RowID if not deleting any records
– NightShade
Mar 22 at 10:28
No, I would say auto-incrementing keys are recommended (they are the RowID in fact). I'm not sure if I really understand the composite primary key of your UserStatus table... "indexing everything" always comes with a price: every index causes additional load on a database write. So only index if it makes sense and the current model really suffers from a bad performance when you query it.
– Oliver Jakoubek
Mar 25 at 13:25
add a comment |
So the activity (in UserActivites) is always one that relates to a (over the time maybe growing) Activities lookup table. The text representation of the activity is in the Activities table and you are just linking to it from your UserActivities table - seems ok so far. You have already a foreign key pointing from UserActivities.ActivityID to Activities.ActivityID (and the same for Username to UserStatus)?
The datetime is just a point in time - no need to put it into some sort of combined index (as the primary key is). You might index the datetime in the future for a better query performance though.
What I would do is:
- throw away the combined primary key on UserActivities
- create a non-meaningful, auto-incrementing integer primary key in the UserActivities table (
ID INTEGER PRIMARY KEY)
Things you should consider:
- create an index on Username and another one on ActivityID in UserActivities; it's not necessary, but recommended that child key columns of foreign keys have an index (https://sqlite.org/foreignkeys.html#fk_indexes)
Your data design looks good that way. You mentioned "and removed overtime" concerning the user activities (if I understood correctly). If so I would create a boolean column in UserActivities for deleted records. That way you can analyze activities that have been removed. I would never delete records once they have been created in the database.
What I meant by removed overtime is that the game may no longer post those activities for the game. I myself would have no need to remove them :) So, if I understand this right, remove the activities table altogether, and the composite-primary key in UserActivities, but place a foreign key pointing to the composite primary key of UserStatus? this sounds like a good model :) would there be any harm in indexing everything here? I also read auto-incrementing keys are not recommended and to use RowID if not deleting any records
– NightShade
Mar 22 at 10:28
No, I would say auto-incrementing keys are recommended (they are the RowID in fact). I'm not sure if I really understand the composite primary key of your UserStatus table... "indexing everything" always comes with a price: every index causes additional load on a database write. So only index if it makes sense and the current model really suffers from a bad performance when you query it.
– Oliver Jakoubek
Mar 25 at 13:25
add a comment |
So the activity (in UserActivites) is always one that relates to a (over the time maybe growing) Activities lookup table. The text representation of the activity is in the Activities table and you are just linking to it from your UserActivities table - seems ok so far. You have already a foreign key pointing from UserActivities.ActivityID to Activities.ActivityID (and the same for Username to UserStatus)?
The datetime is just a point in time - no need to put it into some sort of combined index (as the primary key is). You might index the datetime in the future for a better query performance though.
What I would do is:
- throw away the combined primary key on UserActivities
- create a non-meaningful, auto-incrementing integer primary key in the UserActivities table (
ID INTEGER PRIMARY KEY)
Things you should consider:
- create an index on Username and another one on ActivityID in UserActivities; it's not necessary, but recommended that child key columns of foreign keys have an index (https://sqlite.org/foreignkeys.html#fk_indexes)
Your data design looks good that way. You mentioned "and removed overtime" concerning the user activities (if I understood correctly). If so I would create a boolean column in UserActivities for deleted records. That way you can analyze activities that have been removed. I would never delete records once they have been created in the database.
So the activity (in UserActivites) is always one that relates to a (over the time maybe growing) Activities lookup table. The text representation of the activity is in the Activities table and you are just linking to it from your UserActivities table - seems ok so far. You have already a foreign key pointing from UserActivities.ActivityID to Activities.ActivityID (and the same for Username to UserStatus)?
The datetime is just a point in time - no need to put it into some sort of combined index (as the primary key is). You might index the datetime in the future for a better query performance though.
What I would do is:
- throw away the combined primary key on UserActivities
- create a non-meaningful, auto-incrementing integer primary key in the UserActivities table (
ID INTEGER PRIMARY KEY)
Things you should consider:
- create an index on Username and another one on ActivityID in UserActivities; it's not necessary, but recommended that child key columns of foreign keys have an index (https://sqlite.org/foreignkeys.html#fk_indexes)
Your data design looks good that way. You mentioned "and removed overtime" concerning the user activities (if I understood correctly). If so I would create a boolean column in UserActivities for deleted records. That way you can analyze activities that have been removed. I would never delete records once they have been created in the database.
answered Mar 22 at 9:25
Oliver JakoubekOliver Jakoubek
186116
186116
What I meant by removed overtime is that the game may no longer post those activities for the game. I myself would have no need to remove them :) So, if I understand this right, remove the activities table altogether, and the composite-primary key in UserActivities, but place a foreign key pointing to the composite primary key of UserStatus? this sounds like a good model :) would there be any harm in indexing everything here? I also read auto-incrementing keys are not recommended and to use RowID if not deleting any records
– NightShade
Mar 22 at 10:28
No, I would say auto-incrementing keys are recommended (they are the RowID in fact). I'm not sure if I really understand the composite primary key of your UserStatus table... "indexing everything" always comes with a price: every index causes additional load on a database write. So only index if it makes sense and the current model really suffers from a bad performance when you query it.
– Oliver Jakoubek
Mar 25 at 13:25
add a comment |
What I meant by removed overtime is that the game may no longer post those activities for the game. I myself would have no need to remove them :) So, if I understand this right, remove the activities table altogether, and the composite-primary key in UserActivities, but place a foreign key pointing to the composite primary key of UserStatus? this sounds like a good model :) would there be any harm in indexing everything here? I also read auto-incrementing keys are not recommended and to use RowID if not deleting any records
– NightShade
Mar 22 at 10:28
No, I would say auto-incrementing keys are recommended (they are the RowID in fact). I'm not sure if I really understand the composite primary key of your UserStatus table... "indexing everything" always comes with a price: every index causes additional load on a database write. So only index if it makes sense and the current model really suffers from a bad performance when you query it.
– Oliver Jakoubek
Mar 25 at 13:25
What I meant by removed overtime is that the game may no longer post those activities for the game. I myself would have no need to remove them :) So, if I understand this right, remove the activities table altogether, and the composite-primary key in UserActivities, but place a foreign key pointing to the composite primary key of UserStatus? this sounds like a good model :) would there be any harm in indexing everything here? I also read auto-incrementing keys are not recommended and to use RowID if not deleting any records
– NightShade
Mar 22 at 10:28
What I meant by removed overtime is that the game may no longer post those activities for the game. I myself would have no need to remove them :) So, if I understand this right, remove the activities table altogether, and the composite-primary key in UserActivities, but place a foreign key pointing to the composite primary key of UserStatus? this sounds like a good model :) would there be any harm in indexing everything here? I also read auto-incrementing keys are not recommended and to use RowID if not deleting any records
– NightShade
Mar 22 at 10:28
No, I would say auto-incrementing keys are recommended (they are the RowID in fact). I'm not sure if I really understand the composite primary key of your UserStatus table... "indexing everything" always comes with a price: every index causes additional load on a database write. So only index if it makes sense and the current model really suffers from a bad performance when you query it.
– Oliver Jakoubek
Mar 25 at 13:25
No, I would say auto-incrementing keys are recommended (they are the RowID in fact). I'm not sure if I really understand the composite primary key of your UserStatus table... "indexing everything" always comes with a price: every index causes additional load on a database write. So only index if it makes sense and the current model really suffers from a bad performance when you query it.
– Oliver Jakoubek
Mar 25 at 13:25
add a comment |
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%2f55289823%2fis-this-the-best-way-to-store-this-data%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