I have the need to create a database for some data I have, and so I took a crack at it (as you would hope), and now I need help putting the finishing touches on it! Can you help me normalize this?
I took a picture of the design I created in Excel using fake data:
What you should know is that some games will be played 5v5 and some will be played 3v3. Instead of adding columns for Team1P1, Team1P2, Team1P3, etc., I wanted to leave it up to the experts to help me do this.
Question: Based on my file parser, my application will know whether a game has 6 players (3v3) or 10 (5v5). How can I structure the database to map those players back to the game? Instead of trying to put Player data into the Games table, should I add a column in Players which points to the Game ID ?
Players:
id | player_id | game_id | etc…
Edit for clarification
Picture Starcraft 2, or any other RTS game played online. When a game starts, it is a brand new slate. A set number of players join a match (3v3 or 5v5) and play against each other. At the end of the game, everyone has certain stat values (did they win or lose? How much gold did they have? How many kills, deaths, assists did they have?)
Each of these stats is specific to that player in that game.
If I play 2 games that day, I will look like this:
id | player_id | stat1 | stat2 | stat3 |
1 | 100 | 500 | 600 | 700
2 | 100 | 300 | 999 | 2000
I mostly agree with PeeHaa’s answer, though I have a couple of changes. First, I agree that the
idfields in both the tables you propose, pr0tocol, are confusing since you also havegame_idandplayer_idfields. Just use those.I also agree that you should have a separate
game_playerstable that consists solely ofgame_idandplayer_idand both of those fields combined are the primary key of the table.I feel your
statstable should be keyed the same as thegame_playerstable. This way, not only are you keeping track of each individual player’s stats, but you also have the ability to report statistics for individual games.Edit:
Games:
Players:
Game_Players
Stats
Using these four tables, you can keep track of all stats and be able to separate them based by player or game through whatever reports you choose to write. It doesn’t matter now how many games an individual player is assigned to, since it’s only part of the key in the relevant tables.