views:

176

answers:

5

I am creating a rowing reporting and statistics system for a client where I have a structure at the moment similar to the following:

-----------------------------------------------------------------------------
| ID | Team     | Coaches    | Rowers     | Event     | Position | Time     |
-----------------------------------------------------------------------------
| 18 | TeamName | CoachName1 | RowerName1 | EventName | 1        | 01:32:34 |
|    |          | CoachName2 | RowerName2 |           |          |          |
|    |          |            | RowerName3 |           |          |          |
|    |          |            | RowerName4 |           |          |          |
-----------------------------------------------------------------------------

This is an example row of data but I would like to expand this out to a Rowers table and Coaches table and so on but I don't know how best to then link that back to the Entries table which is what this is.

Has anybody got any words of wisdom they could share with me?

Update

A Team can have any number of Coaches and Rowers, a Rower can be in many Teams (Team A, B, C etc) and a Team can have many Coaches.

+2  A: 

I would go with separate tables for Teams, Coaches, Rowers (maybe Athletes if there are more than one type of sport that you'll want to scale to) and Events.

Teams

TeamID

Coaches

CoachID

Rowers

RowerID

Events

EventID TeamID RowerID

There are a lot of other questions that will further define the relationships, like: What defines the entry (event)? Is it one set of rowers and one coach PER event? Multiple coaches per a set of rowers per event? Are there Teams? What makes up a team?

I'd be asking questions like that...

Optimal Solutions
I got that far but how do I record multiple Rowers and Coaches against a Team and/or Event using your method as it stands?
Ian Roke
Please see my comments to my original post which explain it in a bit more detail.
Ian Roke
You'll have to define a corresponding table between those many-to-many relationships. If you can have multiple teams enter into multiple events then there will be a table in the middle of the two called TeamEvents with the keys of both in them (TeamID, RowerID).. Do you follow?
Optimal Solutions
Please could you provide an example I don't think I understand what you mean?
Ian Roke
If you know you're going to have many-to-many relationships, you should handle that with a table "in between" them that resolves those into a more simple many-to-1 and 1-to-many relationship. If that is the case then my first example wont work for you as its not that simple. So you need to expand the design to handle the complexity.
Optimal Solutions
A sort of link table? How would I then map multiple Rowers and Coaches to one Team?
Ian Roke
You will want to create a table that "defines" that group. As you said, a Team is made up of multiple coaches and multiple rowers. Do then Team table should have a TeamID as well as a RowerID and CoachID. Not to muddy this even more but if a team can have multiple rowers then can it be said, too, that a rower can belong to multple teams? Example: If the Blue team can have John, Mike and Sam could John be on the Blue team as well as the Red team (another team in the system)? If so then you definitely need those resolving tables.
Optimal Solutions
A: 

You say what you posted is "the Entries table," but this table doesn't make much sense, and least not in terms of (one row, no pun intended) = (one fact or thing).

One of the rows in your table is (NULL,NULL,NULL,RowerName3,NULL,NULL,NULL). What does that mean? What is CoachName2 the coach for? And so on.

Or perhaps this is "one row" of your Entries table? If so, it's not a good SQL table, because you have lists of rowers (for example) in a single row-column intersection, and "list-of-rowers" isn't a good choice of data type.

It's impossible to say how to normalize a database if you only look at some data. You need to know what the data means and represents in the business it models.

That said, it looks to me like you at least need separate tables for

Teams Coaches Rowers Events

And then you need to represent aspects of the business scenario like "A rower belongs to exactly one team," "A team has at least one coach, and no coach coaches more than one team."

I don't know what an Entry is from looking at this, but perhaps you need a table for Entries, too. Maybe if I knew about rowing it would make more sense.

Steve Kass
I have added some more context to the data does that help? This is an Access database I have been given to work with. I intend to put this on SQL Server when the structure is normalised better. I agree with you it isn't the best I've ever seen.
Ian Roke
A: 

I would have the following tables:

Team: ID, TeamName Coach: ID, CoachName, TeamID Rower: ID, RowerName, TeamID

Then your Event table would be populated as follows:

Event: ID, TeamID, CoachID, RowerID, EventName, Position, Time

If you wanted to display de-normalized data in a query, you would build something like:

SELECT E.ID, T.TeamName, C.CoachName, R.RowerName, E.EventName, E.Position, E.Time
FROM Event E
INNER JOIN Team T
ON E.TeamID = T.ID
INNER JOIN Coach C
ON E.CoachID = C.ID
INNER JOIN Rower R
ON E.RowerID = R.ID
flayto
+1  A: 

A sort of link table? How would I then map multiple Rowers and Coaches to one Team?

This is my proposal (based on Optimal Solutions' answer):

Team
TeamID
TeamName

Coach
CoachID
CoachName

Rower
RowerID
RowerName

Event
EventID
Position
Time

  1. if you want predefined teams:

CoachTeamLink (link between Coachs and Teams)
TeamID
CoachID

RowerTeamLink (link between Rowers and Teams)
TeamID
RowerID

EventTeamLink (link between Events and Teams)
TeamID
EventID

  1. Or if you dont:

EventCoachLink (link between Events and Coachs)
EventID
CoachID

EventRowerLink (link between Events and Rowers)
EventID
RowerID

Leonel Martins
Thanks Leonel you explained it very well.
Ian Roke
A: 

I'd try something like this::

teams
  id
  name


rowers
  id
  name
  team_id REFERENCES TEAMS (id)

coaches
  id
  name
  team_id REFERENCES teams (id)

events
  id
  name
  starting_time
  length

event_teams
  event_id references events (id)
  team_id references teams (id)
  position
fringd