Download Homework 3 - Spring 2012 | Database Management System | COP 5725 and more Quizzes Computer Science in PDF only on Docsity!
Database Management Systems (COP 5725)
(Spring 2012)
Instructor: Dr. Markus Schneider
TA: Nam Nguyen
Homework 3
Name
UF Id
Email Address
Pledge (Must be signed according to UF Honor Code)
On my honor, I have neither given nor received unauthorized aid in doing this
assignment.
_______________________________________________
Signature
For scoring use only:
Maximum Received
Exercise 1 30
Exercise 2 30
Exercise 3 40
Total 100
Exercise 1 (SQL with Oracle) [30pts]
Consider the following database schema:
City (
ID int,
Name char(35),
CountryCode char(3),
Population int
Country (
Code char(3)
Name char(52),
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica',
'South America'),
Population int,
HeadOfState char(60),
Capital_ID int,
Language (
CountryCode char(3),
Language char(30)
Percentage float(4,1),
Which problem do you find in the database schema above? Describe it, and
propose a solution to this problem.
Import the data for the tables from the files Countries.csv, Cities.csv, and
Languages.csv. Click on the file names to get access to them. Find out how the
import works. Describe how you have imported the data.
Write the following queries in SQL by using the Oracle database system, and print
out the resulting tables of the queries. [4 points each]
Exercise 2 (QBE) [30pts]
Consider the following database schema:
Flight (Flight_Id, Date, From, To)
Passenger (Passenger_Name, Gender)
Ticket (Ticket_Id, Flight_Id, Passenger_Name, Class, Price)
Display the QBE tables that will answer the following questions. [3pts each]
- Print the names of female passengers who have a flight on 11-11-2011?
- Print the names of the passengers who have bought a ticket from a class other than “economy”?
- Print the names of the passengers who pay more than 1000$ for going from London to Rome with the flight dates?
- Print the names of the passengers who have bought more than one ticket for a flight with the Flight_Id’s?
- Which classes have the ticket which has the most expensive price?
- Montreal airport is off on ’11-11-2011’. Cancel all the tickets that from or to Montreal on that date.
- All the flights from Boston in ’11-11-2011’ is postponed to the next day. Update the dates of the flights.
- Print the Flight_Id and the number of passengers in descending order for every flight.
- List all the names of the passenger names for Flight 3333 grouped by their classes.
- Display the average ‘Economy’ class ticket price from London to Rome.
Exercise 3 (SQL and Relational Algebra) [40pts]
Let’s assume a real estate company named Better Homes and the following relations storing information about this company:
Branch (branchNo, street, city, postcode)
Staff (staffNo, fName, lName, position, salary, branchNo)
Client (clientNo, fname, lname, telNo)
PropertyForRent (propertyNo, address, type, rooms, ownerNo, staffno, branchno)
Viewing (clientNo, propertyNo, viewDate, comment)
PrivateOwner (ownerNo, fName, lName, address, telNo)
Registration (clientNo, branchNo, staffNo, dateJoined)
Primary keys are underlined.
(a) Let R 1,... , Rm be relations, A 1, A 2,... , An be any collection of n distinct attributes of the m relations, and F be a valid predicate. Consider the SQL expression
SELECT DISTINCT A1, A2,.. ., An
FROM R1, R2,.. ., Rm
WHERE F
Write down the exact, equivalent Relational Algebra expression. [5pts]
(b) Express the following queries in Relational Algebra:
- List all cities and their zip codes where there is a branch office but no property for rent [5pts]
- List the names and comments of all clients who have viewed a property for rent [5pts]
- Determine all client names who have viewed all properties with three rooms. [5 pts]