FIGURE Q3.12 The Ch03 - Theater Database Tables Database Name: Ch03 - Theater
FIGURE Q3.12 The Ch03 - Theater Database Tables Database Name: Ch03 - Theater
Suppose that you are using the database composed of the two tables shown in
Figure Q3.12.
The foreign key is DIR_NUM, located in the PLAY table. Note that the foreign
key is located on the "many" side of the relationship between director and play.
(Each director can direct many plays ... but each play is directed by only one
director.)
The entity relationship model – both the Chen and Crow’s Foot ERDS are
included -- is shown in Figure Q3.12C.
1 M
DIRECTOR directs PLAY
2. Draw the entity relationship diagram for the relationship between EMPLOYEE
and JOB.
The ERDs – both the Chen and Crow’s Foot versions – are shown in Figure P3.2.
1 M
JOB is assigned to EMPLOYEE
Note: The JOB_CODE = 1 occurs twice in the EMPLOYEE table, as does the
JOB_CODE = 2, thus providing evidence that a JOB can be assigned to many
EMPLOYEEs. But each EMPLOYEE has only one JOB_CODE, so there exists
a 1:M relationship between JOB and EMPLOYEE.
Note: The JOB_CODE = 1 occurs twice in the EMPLOYEE table, as does the
JOB_CODE = 2, thus providing evidence that a JOB can be assigned to many
EMPLOYEEs. But each EMPLOYEE has only one JOB_CODE, so there exists
a 1:M relationship between JOB and EMPLOYEE.
3. Do the tables exhibit entity integrity? Answer Yes or No, and then explain your
answer.
TABLE ENTITY INTEGRITY EXPLANATION
EMPLOYEE Yes Each EMP_CODE value is unique and there are no
nulls.
BENEFIT Yes Each combination of EMP_CODE and PLAN_CODE
values is unique and there are no nulls.
JOB Yes Each JOB_CODE value is unique and there are no
nulls.
PLAN Yes Each PLAN_CODE value is unique and there are no
nulls.
4. Do the tables exhibit referential integrity? Answer Yes or No, and then explain
your answer. Write NA (Not Applicable) if the table does not have a foreign key.
TABLE REFERENTIAL INTEGRITY EXPLANATION
EMPLOYEE Yes Each JOB_CODE value in EMPLOYEE
points to an existing JOB_CODE value in
JOB.
BENEFIT Yes Each EMP_CODE value in BENEFIT points
to an existing EMP_CODE value in
EMPLOYEE and each PLAN_CODE value in
BENEFIT points to an existing PLAN_CODE
value in PLAN.
JOB NA
PLAN NA
5. Draw the entity relationship diagram to show the relationships among EMPLOYEE,
BENEFIT, JOB, and PLAN.
The Chen and Crow’s Foot ERDs are shown in Figure P3.6.
owns
M
1 M
PLAN describes BENEFIT
owns
Use the database shown in Figure P3.23 to answer the following Problems
6. For each table, identify the primary key and the foreign key(s). If a table
does not have a foreign key, write None in the assigned space.
TABLE PRIMARY KEY FOREIGN KEY(S)
TRUCK TRUCK_NUM BASE_CODE, TYPE_CODE
BASE BASE_CODE None
TYPE TYPE_CODE None
NOTE
Note: The TRUCK_SERIAL_NUM could also be designated as the primary
key. Because the TRUCK_NUM was designated to be the primary key,
TRUCK_SERIAL_NUM is an example of a candidate key.
7. Do the tables exhibit entity integrity? Answer Yes or No, and then explain
your answer.
TABLE ENTITY INTEGRITY EXPLANATION
TRUCK Yes The TRUCK_NUM values in the TRUCK table are
all unique and there are no nulls.
BASE Yes The BASE_CODE values in the BASE table are all
unique and there are no nulls.
TYPE Yes The TYPE_CODE values in the TYPE table are all
unique and there are no nulls.
8. Do the tables exhibit referential integrity? Answer Yes or No, and then
explain your answer. Write NA (Not Applicable) if the table does not have a
foreign key.
TABLE REFERENTIAL INTEGRITY EXPLANATION
TRUCK Yes The BASE_CODE values in the TRUCK
table reference existing BASE_CODE
values in the BASE table or they are null.
(The TRUCK table's BASE_CODE is null
for TRUCK_NUM = 1004.) Also, the
TYPE_CODE values in the TRUCK table
reference existing TYPE_CODE values in
the TYPE table.
BASE NA
TYPE NA
A candidate key is any key that could have been used as a primary key, but that was,
for some reason, not chosen to be the primary key. For example, the
TRUCK_SERIAL_NUM could have been selected as the PK, but the TRUCK_NUM
was actually designated to be the PK. Therefore, the TRUCK_SERIAL_NUM is a
candidate key. Also, any combination of attributes that would uniquely identify any
truck would be a candidate key. For example, the combination of BASE_CODE,
TYPE_CODE, TRUCK_MILES, and TRUCK_BUY_DATE is not likely to be
duplicated and this combination would, therefore, be a candidate key. However, while
the latter combination might constitute a candidate key, such a combination would
not be practical. (An extreme – and impractical -- example of a candidate key would
be the combination of all of a table’s attributes.)
NOTE
Some of the answers to the following problem 27 define only a few of the
available correct choices. For example, a superkey is, in effect, a candidate
key containing redundant attributes. Therefore, any primary key plus any
other attribute(s) is a superkey.
Because a secondary key does not necessarily yield unique outcomes, the
number of attributes that constitute a secondary key is somewhat arbitrary.
The adequacy of a secondary key depends on the extent of the end-user's
willingness to accept multiple matches.
BASE_CODE + BASE_CITY + BASE_CITY (This a very effective secondary key, since it is not
likely that a state contains two cities with the same
name.)
references
TYPE
references
TYPE