3

I am modeling a database for use in a softball league website. I'm not that experienced in DB Modeling, and I'm having a hard time with a question about the future.

Right now I have the following tables:

players table (player_id, name, gender, email, team_id)

teams table (team_id, name, captain[player_id], logo, wins_Regular_season, losses_regular_season)

regular_season table (game_id, week, date, home[team_id], away[team_id], home_score, away_score, rain_date)

playoff table (pgame_id, date, home[team_id], away[team_id], home_score, away_score, winnerTo[pgame_id], loserTo[pgame_id])

To make the data persist from season to season, but to also have an easy way to access the data should I:

A) include a year column in the tables and then filter my queries by year? B) create new tables every year? C) Do something else that makes more sense but that I can't think of.

5
  • You don't need the wins/losses in the team table - you have a possiblity for integrity issues there, and you already record wins/losses in the regular_season table and playoff table.
    – JNK
    Mar 14, 2011 at 19:12
  • So when showing a standings page I would query the regular_season table for the games that a team played and what the scores were and then figure out the win/loss records from that? Seems like a lot of work for every time I load that page.
    – Jeremy
    Mar 14, 2011 at 19:36
  • @Jeremy - If all you need is the count of wins/losses, it would simply be a longish WHERE clause along the lines of WHERE (home = XX AND Home_Score > away_Score) OR (away = xx AND away_score > home_score)
    – JNK
    Mar 14, 2011 at 19:38
  • 1
    @JNK - I didn't even think of that. Thanks man that's really slick.
    – Jeremy
    Mar 14, 2011 at 19:41
  • @Jeremy - the danger with having that data in two places is that you don't get it updated in one of them. When you have 5 wins 3 losses recorded in the teams table but the regular_season table shows 4 wins 4 losses, did you mis-record one in the regular_season table or did something get miskeyed in the teams table or both?
    – JNK
    Mar 14, 2011 at 19:41

4 Answers 4

3

This design is not only bad about the future. It is also wrong regarding the past. You're not keeping history in a proper way.

Let's suppose a player changes team: how would that fit into this design? It should be easy to get that kind of information...

And the best way of doing that (IMHO) would be also representing the season as an entity, as a concrete table. Then you should replicate this information in each relationship. Meaning, for instance, that a player does not simply belong to a team: he belongs to a team in a specific season, and may belong to another team when the season changes.

OTOH, I don't think it's wise to keep regular_season and playoff as distinct tables: they could be easily merged into one, by adding some sort of flag in order to keep that information.

Edit This is what I'm meaning:

enter image description here

  • Notice that there is a Season table.
  • A Player belongs to a Team in a Season.
  • NO NEED TO DUPLICATE ANYTHING. A team has only ONE record in the DB; a player will be associated to only ONE record.
  • I did NOT design the Playoff table, because I believe it should not exist. If the OP disagrees, just add it.

That way you can keep track of all seasons, without needing to replicate the whole DB. I think this is also better than using a year column, which is not meaningful, and cannot be easily constrained (like a foreign key can).

But, please, feel free to disagree.

6
  • Players can't change teams during the season in this league. So I think that having a year column in the player table will relate them season by season to their team using the Team_id.
    – Jeremy
    Mar 14, 2011 at 20:02
  • @Jeremy: I don't think you understood me. My answer is also based upon the fact that player's can't change teams during season (it would be much more complex if they could).
    – rsenna
    Mar 14, 2011 at 20:05
  • @Jeremy - What he's saying is, you add a year to the Team table and each team gets a new id each year. Then you easily know who played for the 2010 Bears and the 2011 Bears since they are unique entities/records.
    – JNK
    Mar 14, 2011 at 20:09
  • @rsenna @JNK - That makes sense and I was planning on doing that after we had the conversation about adding year to the different tables.
    – Jeremy
    Mar 14, 2011 at 20:13
  • @JNK: no, I'm NOT saying that... I'll post a diagram, so people can understand (and perhaps stop downvoting me).
    – rsenna
    Mar 14, 2011 at 20:34
2

The standard way would be to add year columns to your tables. That way you can easily call up the past with a select query, or view. SQL Server has good support for this. I've dealt with cleanup of the other route, and it isn't pretty after a few years of data have accumulated.

0

I would go with option A and have a year column in the seasons table and playoff table.

4
  • He'd need it in the players and team tables too, since players can change teams and teams can change captains.
    – JNK
    Mar 14, 2011 at 19:17
  • 1
    Ahh so each year you would have another entry for every player? That would work out very well for maintaining the players stats each season.
    – Tim
    Mar 14, 2011 at 19:25
  • So since we have 2 seasons I could do a column in each table sort of like "2011S" for summer 2011 and "2011F" for fall 2011...but what I worry about is that after 5 or 6 seasons the database will start getting over run with tons of data. Say there are 16 teams with 16 players each that play 15 games each and a playoffs every year that seeds each of the 16 teams in a double elimination style. That's 16 team entries, 16 player entries, and over 100 games per season. Will I run into a space issue on the DB down the line?
    – Jeremy
    Mar 14, 2011 at 19:31
  • 2
    You might be surprised at how many records need to be in a table before you see a real performance hit.
    – Tim
    Mar 14, 2011 at 19:33
0

You already have a date column, you can use that to find the year

SELECT * FROM regular_season WHERE YEAR(date) = 2011
1
  • This wouldn't resolve the issue with players changing teams or captains changing on a team from year to year.
    – JNK
    Mar 14, 2011 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.