Escolar Documentos
Profissional Documentos
Cultura Documentos
17
The airport has a number of tests that are used periodi
ally to ensure that airplanes are still airworthy. Ea
h test has a Federal Aviation Administration (FAA)
test number, a name, and a maximum possible s
ore.
The FAA requires the airport to keep tra
k of ea
h time a given airplane is tested
by a given te
hni
ian using a given test. For ea
h testing event, the information
needed is the date, the number of hours the te
hni
ian spent doing the test, and
the s
ore the airplane re
eived on the test.
1. Draw an ER diagram for the airport database. Be sure to indi
ate the various
attributes of ea
h entity and relationship set; also spe
ify the key and parti
ipation
onstraints for ea
h relationship set. Spe
ify any ne
essary overlap and
overing
onstraints as well (in English).
2. The FAA passes a regulation that tests on a plane must be
ondu
ted by a te
hni
ian who is an expert on that model. How would you express this
onstraint in
the ER diagram? If you
annot express it, explain brie
y.
Answer 2.6
1. Sin
e all airline employees belong to a union, there is a
overing
onstraint on the
Employees ISA hierar
hy.
2. You
annot note the expert te
hni
ian
onstraint the FAA requires in an ER
diagram. There is no notation for equivalen
e in an ER diagram and this is what
is needed: the Expert relation must be equivalent to the Type relation.
The Pres
riptions-R-X
hain of pharma
ies has oered to give you a
free lifetime supply of medi
ine if you design its database. Given the rising
ost of
health
are, you agree. Here's the information that you gather:
Patients are identied by an SSN, and their names, addresses, and ages must be
re
orded.
Do
tors are identied by an SSN. For ea
h do
tor, the name, spe
ialty, and years
of experien
e must be re
orded.
Ea
h pharma
euti
al
ompany is identied by name and has a phone number.
For ea
h drug, the trade name and formula must be re
orded. Ea
h drug is
sold by a given pharma
euti
al
ompany, and the trade name identies a drug
uniquely from among the produ
ts of that
ompany. If a pharma
euti
al
ompany
is deleted, you need not keep tra
k of its produ
ts any longer.
Ea
h pharma
y has a name, address, and phone number.
18
ssn
union_mem_no
Employees
Employee
Figure 2.10
address
capacity
name
model_no
phone_num
ISA
exam_date
weight
salary
Model
Expert
Technician
Traffic_control
Test_info
Plane
Type
Test
score
hours
score
FAA_no
date
reg_no
Chapter 2
name
21
year
title
name
Group
Like_Group
Customer
Classify
price
Artwork
Artist
Like_Artist
Paints
name
cust_id
type
style
amount
name
birthpalce
address
Figure 2.12
age
title, its type of art (e.g., painting, lithograph, s
ulpture, photograph), and its pri
e
must be stored. Pie
es of artwork are also
lassied into groups of various kinds, for
example, portraits, still lifes, works by Pi
asso, or works of the 19th
entury; a given
pie
e may belong to more than one group. Ea
h group is identied by a name (like
those just given) that des
ribes the group. Finally, galleries keep information about
ustomers. For ea
h
ustomer, galleries keep that person's unique name, address, total
amount of dollars spent in the gallery (very important!), and the artists and groups of
art that the
ustomer tends to like.
Draw the ER diagram for the database.
The ER diagram is shown in Figure 2.12.
Answer 2.8
, and
deployment
Chapter 3
28
The
onstraint that the ssn eld of Manages should not be null implies
that for every tuple present in Manages, there should be a Manager. This does not
however ensure that ea
h department has an entry (or a tuple
orresponding to that
dept) in the Manages relation.
Answer 3.10
Exer
ise 3.11 Suppose that we have a ternary relationship R between entity sets A,
B, and C su
h that A has a key
onstraint and total parti
ipation and B has a key
onstraint; these are the only
onstraints. A has attributes a1 and a2, with a1 being
the key; B and C are similar. R has no des
riptive attributes. Write SQL statements
that
reate tables
orresponding to this information so as to
apture as many of the
onstraints as possible. If you
annot
apture some
onstraint, explain why.
Answer 3.11
CREATE TABLE A (
a1
a2
CHAR(10),
CHAR(10),
PRIMARY KEY (a1) )
a1
b1
1
CHAR(10),
CHAR(10),
CHAR(10),
PRIMARY KEY (a1),
UNIQUE (b1),
FOREIGN KEY (a1) REFERENCES A,
FOREIGN KEY (b1) REFERENCES B,
FOREIGN KEY (
1) REFERENCES C )
Answer 3.12
ssn
CHAR(10),
35
Referen
es Telephone Home,
address CHAR(30) )
songId INTEGER,
ssn
CHAR(10),
PRIMARY KEY (ssn, songId),
FOREIGN KEY (songId) REFERENCES Songs,
FOREIGN KEY (ssn) REFERENCES Musi
ians )
Translate your ER diagram from Exer
ise 2.6 into a relational s
hema,
and show the SQL statements needed to
reate the relations, using only key and null
onstraints. If your translation
annot
apture any
onstraints in the ER diagram,
explain why.
In Exer
ise 2.6, you also modied the ER diagram to in
lude the
onstraint that tests
on a plane must be
ondu
ted by a te
hni
ian who is an expert on that model. Can
you modify the SQL statements dening the relations obtained by mapping the ER
diagram to
he
k this
onstraint?
Answer 3.16
ssn
model no
CHAR(11),
INTEGER,
PRIMARY KEY (ssn, model no),
FOREIGN KEY (ssn) REFERENCES Te
hni
ian,
FOREIGN KEY (model no) REFERENCES Models )
model no
INTEGER,
Chapter 3
36
apa
ity
weight
INTEGER,
INTEGER,
PRIMARY KEY (model no))
CHAR(11),
CHAR(20),
CHAR(20),
CHAR(14),
PRIMARY KEY (ssn),
FOREIGN KEY (ssn)
REFERENCES Employees
ON DELETE CASCADE)
ssn
CHAR(11),
exam date DATE,
PRIMARY KEY (ssn),
FOREIGN KEY (ssn)
REFERENCES Employees
ON DELETE CASCADE)
INTEGER,
INTEGER,
PRIMARY KEY (reg no),
FOREIGN KEY (model no) REFERENCES Models)
INTEGER,
CHAR(11),
INTEGER,
INTEGER,
DATE,
INTEGER,
PRIMARY KEY (ssn, reg no, FFA no),
FOREIGN KEY (reg no) REFERENCES Plane Type,
FOREIGN KEY (FAA no) REFERENCES Test,
FOREIGN KEY (ssn) REFERENCES Employees )
37
8. The
onstraint that tests on a plane must be
ondu
ted by a te
hni
ian who is an
expert on that model
an be expressed in SQL as follows.
CREATE TABLE Test info (
FFA no
ssn
reg no
hours
date
s
ore
INTEGER,
CHAR(11),
INTEGER,
INTEGER,
DATE,
INTEGER,
PRIMARY KEY (ssn, reg no, FFA no),
FOREIGN KEY (reg no) REFERENCES Plane Type,
FOREIGN KEY (FAA no) REFERENCES Test,
FOREIGN KEY (ssn) REFERENCES Te
hni
ian emp )
CONSTRAINT MODEL
CHECK ( SELECT * FROM Expert, Type
WHERE Expert.ssn = ssn AND
Expert.model no = Type.model no AND
Type.reg no = reg no )
Consider the ER diagram that you designed for the Pres
riptions-R-X
hain of pharma
ies in Exer
ise 2.7. Dene relations
orresponding to the entity sets
and relationship sets in your design using SQL.
CHAR(11),
CHAR(20),
INTEGER,
CHAR(20),
CHAR(11),
PRIMARY KEY (ssn),
FOREIGN KEY (phy ssn) REFERENCES Do
tor )
CHAR(11),
CHAR(11),
CHAR(11),
INTEGER,
CHAR(20),
CHAR(11),