|
CSCI A114 / INFO I111
|
Grades will be posted on-line.
First, let's review the rules of relational database design.
We use the entity-relationship model. We also said that this model does an adequate, albeit imperfect, job of modeling real-world situations, such as business enterprises or the records kept by schools, hospitals, governments, and so on, where database systems are likely to be used. However, if we view the structures defined in the entity-relationship model as conceptual schemes, we shall not be grossly deceived.
So we will have the following recipe:
Make a table for each relationship, in which the columns are keys in the tables for the entities that the relationship is connecting.
Please apply this rule to the following problem for which the E-R diagram is given. Then store in the database (by hand) the facts listed at the bottom of the assignment.
Assume a database that records baseball players, the teams they played for, their batting averages and positions played. Consider the following analysis of entities and relationships.
The entities are:
PLAYERS with attributes: AttributeNAME HOME /* place of birth */ BDATE /* date of birth */
NAME will be the key.
POSITIONS with attributes: Let's takePOSNAME /* e.g., pitcher */ POSNUMBER /* 1 for pitcher, 2 for catcher ... */
POSNAME to be the key.
TEAMS with attributes: TheFRANCHISE /* explained below */ CITY YEAR
FRANCHISE attribute is a unique identifier we give to a baseball franchise.
As a franchise is a property, it has existence as an entity even when it moves to another city
or changes its name. A team (as opposed to a franchise) is the collection
of players, coaches, etc., working for a franchise in a given year. The key for the entity set
TEAM is FRANCHISE and YEAR.
BA, the set of batting averages.
This entity set has one attribute, PCT, whose values are three digit decimal numbers
between 0 and 1. Clearly, PCT is the key.
Relationships:
SEASON between PLAYERS, TEAMS, and BA.
Notice that this is a ternary relationship (arity 3). It is many-one from PLAYERS and TEAMS
to BA in the sense that given a player and a team that player has a unique batting average. Recall that
a "team" exists for one particular year, so the typical player is on many teams and has many batting averages, but
just one batting average per year.
PLAYS between PLAYERS and POSITIONS. This is a many-many
relationship indicating what positions were played by a player, over the course of his career.
Now please enter the following data in the database:
George Ruth was born in Baltimore, MD, in February 6, 1895. He played for the Red Sox and averaged 0.325 in 1916. He also averaged 0.393 for the Yankees in 1923. Tyrus Cobb was born in Narrows, GA, on February 18, 1866. He could play center field and first base. He played for the Tigers in 1911, with a batting average of 0.420 in a year when the Tigers where located in Detroit. Jack Robinson was born in Cairo, GA, on January 31, 1919. He played for the Dodgers (in Brooklyn) in 1949, and had a 0.342 batting average that year. The Red Sox were located in Boston in 1917. Stanley Musial had a batting average of 0.376 in 1948 for the Cardinals. Stanley Musial used to play first base. The position number for first base is 3. Other position numbers are: 1 for pitcher, 2 for catcher, and so on.Note: you need to draw the tables and actually enter the data in the tables, on paper, by hand.
A114/I111