Mysql – Best way to design tournament database

database-designMySQL

I'm creating a webpage for placing bets on all matches of the upcoming Euro 2012 football tournament. Need some help deciding what approach to take for the knockout phase.

I have created a mockup below, which i'm pretty satisfied with when it comes to storing the results of all "known" group stage matches. This design makes it very easy to check if a user has placed a correct bet or not.

But what is the best way to store the quarter and semi finals? Those matches depend on the outcome in the group stage.

One approach I thought of was adding ALL matches to the matches table, but assign different variables or identifiers to the home/away teams for the matches in the knockout phase. And then have some other table with those identifiers mapped to teams… This could work, but does not feel right.

Basic database design

Best Answer

I'd start off by trying to fix all the predetermined information in the model itself including

  • dates/venues
  • structure (ie group/knockout stages)
  • rules (ie points scoring, tie-break rules)

Some of this information will be data in tables, some will be codified logic in views.

Something like this perhaps:

  • team(team_id, group_code enum('A', 'B', 'C', 'D'), name)
  • match(match_id, kickoff_at)
  • group_match(match_id, team_id_home, team_id_away, group_code)
  • knockout_match(match_id, knockout_code enum('Q1', 'Q2', 'Q3', 'Q4', 'S1', 'S2', 'F')
  • result(match_id, score_home, score_away)

Information such which teams play in Q1 never needs to be stored directly because it can be calculated from the group stage results. The only changes to make as the tournament progresses are inserts into the result table.

Related Question