Reputation: 618
I just started learning about databases and therefore i need a bit of help with the design of my database. I am trying to make an achievment system and I am a bit stuck mostly because im worried my design isn´t that good. I have come up with 2 solutions the first is show here: link 1.
So basicly I got a user who has some ingameData. There will be a record of every game he has played and therefor I don't need data like total[xyz], where xyz could be any stat as I can just get those with queries. My problem lies on the other side. I got Many users who got many Achievments.
What I have learned so far is that you should always have your forigen key in your many relation table so I would need to add another table as shown here in my 2 solution: Link 2. Here I have that Many users has one achievement table and many achievments belong to one achievment table. Is my connectivity wrong here? and/or is my design really flawed? This is my first real datebase design, so I am a bit clueless
Upvotes: 0
Views: 3211
Reputation: 76
Standard way to model a many to many is to introduce a link table. You create a link between the User and the Achievement.
Conventionally called UserAchievement this contains two columns UserId and AchievementId both fks to their respective table.
When an achievement is gained you just add another entry.
Upvotes: 6