Question

I'm trying to figure out the best way to manage this data storage problem....

I have a table of players, teams, and competitions.

A team may be involved in let's say 3 competitions.

A player belongs to a team, but may only be eligible to play in 2 of the 3 competitions that his or her team plays in. Likewise another player of the same team may be eligible for all 3.

I don't want to add a column to the player table for each competition as I'm then moving away from the relational model. Do I need another table 'competition_eligiblity' - this seems like a lot of work though!

Any suggestions?

Thanks,

Alan.

Was it helpful?

Solution

Yes, you do need a table for competition eligibility.

It really is no more work to put it there. Actually, it will be less work:

  • Adding a new competition in the future will be a real pain if it involves adding a new column to a table.
  • If the competition eligibility is stored in columns, performing a query to get information on eligibility becomes a nightmare.

Suppose you wanted to list all the competitions players are eligible for. Here would be your query:

select player, "competition1" from players where competition1_eligible = 1
   union all
select player, "competition2" from players where competition2_eligible = 1
   union all
select player, "competition3" from players where competition3_eligible = 1
   union all
select player, "competition4" from players where competition4_eligible = 1

Sounds like fun, eh? Whereas, if you have an eligibility table, this information will be very simple to get.

Update: storing all the eligibility info in a single value would be even more of a nightmare, because imagine trying to extract that information back out of the string. That is beyond the limits of a sane SQL query.

Creating a new table is really a trivial piece of work, and you only have to do that once. Everything after that will be much easier if you do it that way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top