Sie sind auf Seite 1von 6

Dr.

Stefan Brass January 5, 2000


S hool of Information S ien es
University of Pittsburgh

INFSCI 2710 \Database Management"


| Example for Midterm Exam |

Instru tions
 This is the midterm exam from the Spring 1999 edition of the ourse.
 There were 2 hours, 50 minutes time for solving the exer ises.
 Note that the midterm exam in this ourse will in lude some new types of exer ises.
I will give some hints during the last le ture before the exam and on the web page.
There may be some multiple hoi e exer ises.
 Examples of new types of exer ises are, e.g.:
{ Find errors in relational algebra queries.
{ Given pairs of relational algebra queries, whi h ones are equivalent?
{ Given pairs of ER-s hemas, whi h ones are equivalent.
{ Given fun tional dependen ies, determine a key.
 However, it will ertainly be a good preparation to do these example exer ises under
exam-like onditions. Do it relatively early so that you still have time to pra ti e
more or ask questions if you nd this exam diÆ ult.
 In the real midterm exam, spa e for the solutions will be provided.
 You may use books and notes in the exam. But don't forget that the time is limited.
Books will only help if you know exa tly where to sear h (i.e. just must have read
them before). It might be helpful to make your own summary notes when you repeat
the material for the exam.
 If you do not understand the exer ises, please ask (also during the real exam).
 The midterm exam will be on February 23. Please he k the web page for any
hanges.

Exer ise 1 (ER Design) 10 Points

Please design an ER-S hema for a very simpli ed database of a physi ian (do tor). The
physi ian wants to store data about:
INFSCI 2710 \Database Management" | Midterm Exam (Spring 1999) 2

 Patients: So ial se urity number, rst name, last name.


 Some, but not all patients belong to a health management organisation (HMO). In
this ase, also the organisation name and membership number has to be stored.
 Meetings with patients (appointments): Whi h patient ame on whi h day to the
do tors oÆ e. You an assume that there annot be two meetings with the same
patient on the same day (or else this would somehow be treated as a single meeting).
The do tor wants to store the diagnosis or some other text about ea h su h meeting.
For simpli ity, you do not have to onsider s heduled meetings (lying still in the
future).
 Pres riptions: Whi h drug was pres ribed to a patient on a spe i day (as an
out ome of a meeting). It is possible that several drugs are pres ribed to a patient
in a single meeting.
 Drugs: The name of the drug and some information about the drug olle ted in a
single text-valued attribute (so you do not have to worry about any internal stru ture
in this information).
Note that the do tor wants to keep histori al information (data about past meetings and
pres riptions).
Please de ne also keys and ardinalities. If other onstraints should be needed, it
suÆ es to sket h them in natural language.

Exer ise 2 (ER to Relational Mapping) 10 Points

You are given the following ER-S hema for a simpli ed airline database. It ontains
information about:
 Airports: The airport id (e.g. PIT, JFK) and the name of the ity.
 Flight Routes: The number of the ight (e.g. \US 781"), the airport from whi h the
ight starts and the goal airport (e.g. from Frankfurt to Pittsburgh), and the planned
departure and arrival times (e.g. 11:35 and 14:45). For simpli ity, intermediate stops
are not represented.
 Flight Instan es: A ight s heduled for a parti ular date, e.g. ight \US 781" on
February 25. Also the en onomy lass pri e for this ight instan e is stored (it
depends on the date).
 Employees: Their so ial se urity number and name.
 Crew Assignments: Whi h employee is s heduled to work on whi h ight instan e?
For simpli ity, di erent types of employees (e.g. pilots and stewards) are not repre-
sented.
INFSCI 2710 \Database Management" | Midterm Exam (Spring 1999) 3

 

Departure

 
  
 
(1; 1)  from PP (0; )
   P PP ID

  HHH 
No Flight
 Airport
P PP  
(0; ) (1 1)
;
PP
to
 (0 ) ;  City

 


 has  Arrival

 H 
 
 Date
HH (1; 1)

Instan e
(0; )

Crew
(0; )
Employee

HHH
SSN


 Pri e
  
 Name

Translate this s hema into the relational model. Spe ify keys, foreign keys, and not null
onstraints. If further onstraints are needed to make the relational s hema equivalent to
the ER-s hema, please explain them in natural language.

Exer ise 3 (Constraints) 2 Points

Please explain one additional onstraint for the ights database whi h ex ludes impossible
database states. You do not have to spe ify the onstraint formally. Only explain a
situation whi h the ER-s hema allows, but whi h annot happen in the real world.
INFSCI 2710 \Database Management" | Midterm Exam (Spring 1999) 4

Example Database for Exer ises 4 to 7

The following relational database ontains information about multivitamin/multimineral


tablets (nutrition supplements). It onsists of three relations (tables):
 Supplement(Name: string, Produ er: string not null)

Supplement
Name Produ er
Centrum Lederle
One A Day Bayer
.. ..
. .
 Vitamin(Substan e: string, Daily Value: number not null, Unit: String not null)
/* Despite the name, this relation also ontains minerals et . */
Vitamin
Substan e Daily Value Unit
Vitamin A 5000 IU
Vitamin C 60 mg
Biotin 300 m g
Iron 18 mg
.. .. ..
. . .
 Contents(Name ! Supplement, Substan e ! Vitamin, Quantity: number not null)
/* Quantity is the ontents in one tablet, same units as in table \Vitamin" */
Contents
Name Substan e Quantity
Centrum Vitamin A 5000
One A Day Vitamin A 5000
Centrum Vitamin C 60
One A Day Vitamin C 60
Centrum Biotin 30
Centrum Iron 18
One A Day Iron 27
.. .. ..
. . .
All attributes are not null. Sin e the \not null" onstraint is implied by the primary key
onstraint, it is expli itly listed only for the non-key attributes.
Of ourse, the database state is only an example. Your queries must work with any
database state.
INFSCI 2710 \Database Management" | Midterm Exam (Spring 1999) 5

Exer ise 4 (Relational Algebra) 9 Points

Formulate the following queries in relational algebra:


a) Whi h nutrition supplements ontain \Iron"? List the name of the supplement and
the quantity of iron.
b) List all substan es (Vitamins and Minerals) whi h are ontained in the nutrition
supplement \Centrum". Print the name of the substan e, the quantity, and the unit
(IU, mg, m g, et .).
) Whi h nutrition supplements ontain more than the re ommended daily value of any
of their substan es? List name, produ er and the substan e.

Exer ise 5 (Relational Algebra, Advan ed Queries) 6 Points

Please formulate also the following queries to the multivitamin tables database in rela-
tional algebra:
a) Whi h nutrition supplements (the name suÆ es) do not ontain \Biotin".
b) Whi h nutrition supplements ontain \Vitamin C", but no other Substan es? So you
have to sele t only the pure Vitamin C tablets. Print name and produ er. You an
assume that all tablets ontain at least one substan e (there are no dummies). So
it suÆ es to he k that the supplement ontains no other substan e (then it must
automati ally ontain Vitamin C).

Exer ise 6 (SQL) 9 Points

Formulate the queries of Exer ise 4 also in SQL:


a) Whi h nutrition supplements ontain \Iron"? List the name of the supplement and
the quantity of iron.
b) List all substan es (Vitamins and Minerals) whi h are ontained in the nutrition
supplement \Centrum". Print the name of the substan e, the quantity, and the unit
(IU, mg, m g, et .).
) Whi h nutrition supplements ontain more than the re ommended daily value of any
of their substan es? List name, produ er and the substan e.
INFSCI 2710 \Database Management" | Midterm Exam (Spring 1999) 6

Exer ise 7 (Reverse Engineering) 5 Points

De ne an ER-s hema whi h orresponds to the above \Nutrition Supplement" database.


So when your ER-s hema is translated into the relational model, the result should be
exa tly the given relational s hema.

Exer ise 8 (BCNF) 2 Points

Suppose you have a relation


Homework Result(Student ID, Exer ise No, Points, Max Points)
and the following two fun tional dependen ies:
 Student ID, Exer ise No ! Points
 Exer ise No ! Max Points
Is the relation in BCNF? Please give a short explanation of your answer.

Exer ise 9 (ER Diagrams) 4 Points

The following ER-s hema ontains (at least) 4 errors. Please identify them.

   
  
A2

  HHH 
A1 E1
(0; )
 R2  (0; )
E2

(0; ) 
 (0; )  B

  C
 

 R1   R3
 
  (1; ) (1; 1)
 
  A3 E3 E4
  A4

Das könnte Ihnen auch gefallen