Fundamentals of Database Systems - Computer Science

advertisement
The American University in Cairo
Computer Science Department
CSCI 253
“Fundamentals of Database Systems”
Dr. KHALIL
Spring 2007
Final Exam
Last name : .............................................................................
ID
First Name : .............................................................................
Form I
*
*
*
*
*
*
*
.................................................
Do not turn this page until asked to do so.
Exam time is 120 minutes.
Put the answers on the same question sheet, do not use any additional papers, even for scratch.
Write your name, ID, section no. in the indicated places.
Read the exam instructions.
Read the Academic Integrity Policy.
Sign the following statement.
Academic Integrity Policy
Cheating in Exams is a violation of the Academic Integrity Policy of AUC. Whispering, talking, looking at
someone else’s paper, or copying from any source is considered cheating. Any one who does any of these actions
or her/his answers indicates that she/he did any of them, will receive a punishment ranging from zero in this exam
to failing the course. If repeated, it may lead to dismissal from AUC.
I have read the Academic Integrity Policy and exam instructions and I am presenting this exam
as entirely my effort.
Signature: _______________
---------------------------------------------------------------------------------------------------------------------------
DO NOT USE THIS SECTION
Question
Points
1
35
2
35
3
15
4
15
Total
100
Grade
1
QUESTION 1 (35 points)
A trucking company is responsible for picking up scheduled regular shipments from different
warehouses and delivering these shipments to individual supermarkets. A shipment is just a
quantity of a specific item that is scheduled to be delivered to a specific supermarket from a
specific warehouse by a specific truck (each scheduled shipment is taken from one warehouse,
carried by one truck, and delivered to one supermarket). A truck may carry several shipments
from several warehouses for several supermarkets. A warehouse stores and delivers only one
kind of items. A supermarket may be supplied by several shipments from several warehouses
by several trucks. It is only required to keep track of the type (type of item), quantity, and date
of each regular scheduled shipment delivered to each supermarket from each warehouse and
carried by each truck. Design the appropriate ER-schema diagram for the given data
requirements Specify all key attributes and all structural constraints. Give also the
corresponding relational schema. Specify all integrity constraints for each defined relation.
Design the appropriate ER-schema diagram for the given data requirements Specify all key
attributes and all structural constraints. Give also the corresponding relational schema. Specify
all integrity constraints for each defined relation.
ER Schema Diagram
2
Relational Schema Diagram
3
How would be the ER and the relational schemas for the same data requirements but with
the constraint: each truck is allowed to deliver shipments for only one supermarket?
You can show only the changes in both the ER and Relational Schemas.
ER Schema Diagram
Relational Schema Diagram
4
QUESTION 2 (35 points)
Consider the given Relational database schema for an Airlines application. The primary key of
each relation is underlined.
Flight (FlightNo)
FlyON (FlightNO, WeekDay)
FlightLeg (FlightNo, LegNo, DepartureTime, DepartureAirportCode, ArrivalTime, ArrivalAirportCode)
FlightLegInstance
(FlightNo,LegNo,Date,
ActualDepartureTime,
ActualDepartureAirportCode,
ActualArrivalTime, ActualArrivalAirportCode, AirplaneType, AirplaneNo)
Airport (AirportCode, AirportCity)
AirplaneType (AirplaneType, ManufacturingCompany, SeatCapacity)
Airplane (AirplaneType, AirplaneNo, ManufacturingYear, Status)
CanLand (AirplaneType, AirportCode)
FlightLegFares (FlightNo, LegNo, Class, FareValue)
Using DDL/DML of SQL2, write the appropriate statements to perform the following operations:
a. Write a complete schema (you have to specify all necessary entity and referential
constraints) for the table FlightLegInstance. Assume appropriate data types for the
underlying attributes.
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
5
b. Retrieve the total number of all flights that fly only on Sundays.
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
c. List the flight number, day and time of all flights that depart from Cairo airport with
destination JFK New York airport. The flights should be displayed in an ascending order
according to day and time.
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
6
d. Get all Airplane types that can land on “Hurgada” and “Sharm El-Sheikh” airports but
not on “Luxor” airport.
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
7
e. Define a view to get the total number of flying trips (flight leg instances) for each
airplane during the last year (2006). Write a query to display such airplanes with
more than 200 trips.
The View
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
The Query
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
8
QUESTION 3 (15 points)
Consider again the same Relational database schema for the Airlines application with all the
tables and views are already created. Suppose that Moustafa is the DBA of this database and
he wants to grant the following privileges to users’ accounts Eman, Wael, Sherif, and Menna.
Write SQL statements to grant these privileges:
1. Account Eman can retrieve and modify all information of Flight, FlyOn, and
FlightLeg.
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
2. Account Wael can retrieve only the FlightLegInstances’ data of only those
departing from Cairo airport.
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
9
3. Account Sherif can only modify the FareValue of FlightLegFare.
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
4. Account Menna can only get the total number of flying trips (flight leg
instances) for each airplane during the last year (2006).
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
10
Question 4 (15 points)
Consider relation SAP to represent sales of products by different salesmen in different
areas. Each salesman can work in only one area.
SAP (Sno, Sname, Aname, Pno, Qty)
Sno
Sname
Aname
Pno
Qty
1.
2.
:
:
:
:
:
where,
Salesman number, (unique) for each salesman,
Salesman name,
Area name, (unique) for each area,
Product number, (unique) for each product,
Quantity of the product sold by the salesman in his/her area.
In which Normal form is relation SAP? Why?
Normalize relation SAP to the most desirable form showing up the normalization
process.
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
11
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
...............................................................................................................................................................................................................................
Good luck
12
Download