[an error occurred while processing this directive] [an error occurred while processing this directive]
![]() |
|
To learn how to design a relational database we will work on a specific problem of building a database for a football league. Below is a description of all the data we need to keep track of.
A fictitious football league (FFL) has a few teams. The league hopes to expand and be able to add more teams in the future. Each team has a unique name, a coach and a phone number to contact the team and the coach. A team has many players. A player plays for one team and has a name and an age. In the game of football, there are many player positions, each of which has a unique name and a specific description of what the position is. A player can play one or more positions. For example, a player can play both as a running back and as a wide receiver. Obviously any position can be played by many different players. For example, many players can be a quarterback.
The best way to store the above data is to organize them into tables and store them in a relational database.
The first order of business is to decide what the principal tables are. At first glance, we see that we need at least three tables whose designs are listed below.
Field Name | Data Type | Description |
TeamName | Text | Primary Key |
CoachName | Text | |
CoachPhone | Text |
Field Name | Data Type | Description |
TeamName | Text | Foreign Key from the Teams table. NOTE: this should NOT be a key. |
PlayerName | Text | |
PlayerAge | integer |
How do we keep track of a player's positions? We shall answer this
question in the Many-to-Many relationship section.
Field Name | Data Type | Description |
PostionCode | Text | Primary Key |
PostionName | Text | |
Description | Text |
The above table designs can be easily created using MS ACCESS.
In class: hands-on exercise to build the above table in a database called football. Be sure to remember where you save the database.
"A teams has many players while a player can play only for one team." This is an example of what is called "one-to-many" relationship. In addition to storing this relationship in the database, we want to tell the database that the team name for each of the players in the Players table can only reference a valid team name in the Teams table. This is an example of what is called "referential integrity." This is an EXTREMELY IMPORTANT property in relational database design. In MS ACCESS, this is best achieved using the lookup wizard in the design of the Players table.
In class: hands-on exercise on how to use the lookup wizard to create a one-to-many relationship with referential integrity between Teams and Players.
IMPORTANT: In order to establish a one-to-many relationship between a main table and a related table, the main table must have a key field and the related must have a foreign key that matches (i.e. has the same type) with the main table's key.
In class hands-on exercise.
"A player can play one or more positions, while any position can be played by many different players." This is an example of what is called many-to-many relationship. To express this relationship in a relational database, we need an auxiliary table, say PlayersPositions that serves as a "hub" to which we connect the table Players and the table Positions. First, we need to modify the design of Players by adding a key to it.
Field Name | Data Type | Description |
PlayerID | Use Lookup Wizard | Foreign Key from Players |
PostionCode | Use Lookup Wizard | Foreign key from Positions |
Description | Text |
In the end, we see that a many-to-many relationship between two tables consists of a pair of one-to-many relationships between each of the tables and an additional intermediary table.
Now that we have the database design in place, we can start entering data. Since in a one-to-many relationship, the related table can only reference a key field in the main table, we must enter the data in the main table BEFORE entering the related data in the related table. In the above example, we must enter data in the following order:
Click here to download the completely designed football database
© Dung X. Nguyen
Last revised 12/02/2005 10:02 AM