Você está na página 1de 7

Introdu

tion to Database Design

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

The ER diagram is shown in Figure 2.10.

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 o ered 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:

Exer ise 2.7

Patients are identi ed by an SSN, and their names, addresses, and ages must be
re orded.
Do tors are identi ed 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 identi ed 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 identi es 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

ER Diagram for Exer ise 2.6

salary
Model

Expert

Technician

Traffic_control

Test_info

Plane

Type

Test

score

hours

score

FAA_no
date

reg_no

Chapter 2

name

Introdu tion to Database Design

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

ER Diagram for Exer ise 2.8

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 lassi ed 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 identi ed 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

Answer the following questions.

Exer ise 2.9

Explain the following terms brie y:

UML, use ase diagrams, state hart dia-

grams, lass diagrams, database diagrams, omponent diagrams


diagrams

Explain the relationship between ER diagrams and UML.


Answer 2.9

Not yet done.

, 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

The following SQL statement reates Table A:

CREATE TABLE A (

a1
a2

CHAR(10),
CHAR(10),
PRIMARY KEY (a1) )

Tables B and C are reated similarly to A.


CREATE TABLE R (

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 )

We annot apture the total parti ipation onstraint of A in R. This is be ause we


annot ensure that every key a1 appears in R without the use of he ks.
Consider the s enario from Exer ise 2.2, where you designed an ER
diagram for a university database. Write SQL statements to reate the orresponding
relations and apture as many of the onstraints as possible. If you annot apture
some onstraints, explain why.
Exer ise 3.12

Answer 3.12

The SQL statements are as follows:

1. CREATE TABLE Tea hes (

ssn

CHAR(10),

The Relational Model

35
Referen es Telephone Home,

FOREIGN KEY (ssn) REFERENCES Musi ians )

7. CREATE TABLE Pla e (

address CHAR(30) )

8. CREATE TABLE Perform (

songId INTEGER,
ssn
CHAR(10),
PRIMARY KEY (ssn, songId),
FOREIGN KEY (songId) REFERENCES Songs,
FOREIGN KEY (ssn) REFERENCES Musi ians )

9. CREATE TABLE Album Produ er ( albumIdenti er INTEGER,


ssn
CHAR(10),
opyrightDate DATE,
speed
INTEGER,
title
CHAR(30),
PRIMARY KEY (albumIdenti er),
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.

Exer ise 3.16

In Exer ise 2.6, you also modi ed 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 de ning the relations obtained by mapping the ER
diagram to he k this onstraint?
Answer 3.16

The following SQL statements reate the orresponding relations.

1. CREATE TABLE Expert (

ssn
model no

CHAR(11),
INTEGER,
PRIMARY KEY (ssn, model no),
FOREIGN KEY (ssn) REFERENCES Te hni ian,
FOREIGN KEY (model no) REFERENCES Models )

The parti ipation onstraint annot be aptured in the table.


2. CREATE TABLE Models (

model no

INTEGER,

Chapter 3

36
apa ity
weight

INTEGER,
INTEGER,
PRIMARY KEY (model no))

3. CREATE TABLE Employees ( ssn


CHAR(11),
union mem no INTEGER,
PRIMARY KEY (ssn))
4. CREATE TABLE Te hni ian emp ( ssn
name
address
phone no

CHAR(11),
CHAR(20),
CHAR(20),
CHAR(14),
PRIMARY KEY (ssn),
FOREIGN KEY (ssn)
REFERENCES Employees
ON DELETE CASCADE)

5. CREATE TABLE Tra ontrol emp (

ssn
CHAR(11),
exam date DATE,
PRIMARY KEY (ssn),
FOREIGN KEY (ssn)

REFERENCES Employees
ON DELETE CASCADE)

6. CREATE TABLE Plane Type ( reg no


model no

INTEGER,
INTEGER,
PRIMARY KEY (reg no),
FOREIGN KEY (model no) REFERENCES Models)

7. 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 Employees )

The Relational Model

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. De ne relations orresponding to the entity sets
and relationship sets in your design using SQL.

Exer ise 3.17

The statements to reate tables orresponding to entity sets Do tor,


Pharma y, and Pharm o are straightforward and omitted. The other required tables
an be reated as follows:
Answer 3.17

1. CREATE TABLE Pri Phy Patient ( ssn


name
age
address
phy ssn

CHAR(11),
CHAR(20),
INTEGER,
CHAR(20),
CHAR(11),
PRIMARY KEY (ssn),
FOREIGN KEY (phy ssn) REFERENCES Do tor )

2. CREATE TABLE Pres ription ( ssn


phy ssn
date
quantity
trade name
pharm id

CHAR(11),
CHAR(11),
CHAR(11),
INTEGER,
CHAR(20),
CHAR(11),

Você também pode gostar