Reputation: 31
I'm working on an application where users create an account and will create a collection of games that they own and rate them. I am not sure how to store this efficiently in a database. Because each user will have their own list, and different users could have the same games, I'm unsure how to store them without having to create many records for one game that has many users that own it. I'm not very good at explaining so just in case that was worded in a weird way I'll provide an example. Let's say 10 users play GTA V, I don't want to have a record for each user's copy of GTA V, which would make 10 records just for that game. Because of this, storing user's games in a single table isn't really ideal.
I thought of storing this data in JSON documents or text documents and have one document for each user, which would then be stored in the database, but I've read that this isn't always a good idea. I can't think of any other way to store it without having loads of duplicate records that I don't need. There is also the problem of having to edit these documents whenever I add or edit a game So would storing documents be good in this situation? Is there a better way? As for a database, should I go SQL or NoSQL? Thank you.
Upvotes: 2
Views: 1101
Reputation: 404
Well, it depends on the environment that you want to apply your application. If it has a MySQL, SQL Server, or Oracle Database backend you should go with SQL, or if it a MongoDB you should go with NoSQL.
I suppose you want build a web application with a SQL database. So, the best approach for you database would be to create the following tables:
users
games
user_favorites
To better describe it, I have drawn a schema for it
Please let me know if you needed more clarification
Upvotes: 2