12.11.2014 Views

CPSC 304 Database Management Systems ... - Ugrad.cs.ubc.ca

CPSC 304 Database Management Systems ... - Ugrad.cs.ubc.ca

CPSC 304 Database Management Systems ... - Ugrad.cs.ubc.ca

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>CPSC</strong> <strong>304</strong> <strong>Database</strong> <strong>Management</strong> <strong>Systems</strong><br />

Tutorial 5 – Review Session before Midterm I<br />

FDs and Normal Forms<br />

(some questions will be skipped in the tutorial)<br />

Problem 1: Consider a relation R with five attributes ABCDE. You are given the<br />

following dependencies:<br />

A ! B, BC ! E, ED ! A.<br />

1. List all of the <strong>ca</strong>ndidate keys for R.<br />

2. Is R in 3NF?<br />

3. Is R in BCNF?<br />

Problem 2: Consider the schema with attributes ABCD and FDs:<br />

AB ! C, C ! A, C ! D.<br />

1. Produce a lossless BCNF decomposition for this schema.<br />

2. Is it dependency-preserving? Explain why. If not, produce a dependencypreserving<br />

3NF decomposition.<br />

Problem 3: Suppose you are given a relation R(A,B,C,D). For each of the<br />

following sets of FDs, assuming they are the only dependencies that hold for R,<br />

identify the <strong>ca</strong>ndidate key(s) for R.<br />

1. B!C, D!A.<br />

2. A!BC, C!AD<br />

3. A!B, B!C, C!D<br />

Problem 4: (Exercise 19.5 of the book) Consider the following collection of<br />

relations and dependencies. Assume that each relation is obtained through<br />

decomposition from a relation with attributes ABCDEFGHI and that all the<br />

known dependencies over relation ABCDEFGHI are listed for each question. (The<br />

questions are independent of each other, obviously, since the given dependencies<br />

over ABCDEFGHI are different.) For each (sub)relation:<br />

(a) State the strongest normal form that the relation is in.<br />

(b) If it is not in BCNF, decompose it into a collection of BCNF relations.<br />

1. R1(A,C,B,D,E), A → B, C → D<br />

2. R2(A,B,F), AC → E, B → F<br />

3. R3(A,D), D → G, G → H<br />

4. R4(D,C,H,G), A → I, I → A<br />

5. R5(A,I,C,E)<br />

1


Problem 5: (Exercise 19.7 of the book) Suppose you are given a relation R with<br />

four attributes ABCD. For each of the following sets of FDs, assuming those are<br />

the only dependencies that hold for R, do the following:<br />

(a) Identify the <strong>ca</strong>ndidate key(s) for R.<br />

(b) Identify the best normal form that R satisfies (3NF, BCNF, or none).<br />

(c) If R is not in BCNF, decompose it into a set of BCNF relations that<br />

preserve the dependencies.<br />

1. C → D, C → A, B → C<br />

2. B → C, D → A<br />

3. ABC → D, D → A<br />

4. A → B, BC → D, A → C<br />

5. AB → C, AB → D, C → A, D → B<br />

RA, DRC and SQL<br />

Problem 6: Consider the following schemas:<br />

Branch (bname, assets, bcity)<br />

Customer (cname, street, ccity)<br />

Deposit (bname, account#, cname, balance)<br />

Borrow (bname, loan#, cname, amount)<br />

Rewrite the English queries below using:<br />

(a) Relational algebra<br />

(b) SQL<br />

1. Find all customers having a loan at the bank and the cities in which they live.<br />

2. Find the largest account balance in the bank.<br />

3. Find all the customers who have an account at all branches lo<strong>ca</strong>ted in<br />

Vancouver.<br />

Problem 7: Using the same schemas as in Problem 6, tell what the English<br />

meanings of the following DRC queries are.<br />

1. { < b , l,<br />

c,<br />

a > | < b,<br />

l,<br />

c,<br />

a >∈borrow<br />

∧ a > 1200}<br />

2. { < c > | ∃b,<br />

l,<br />

a(<br />

< b,<br />

l,<br />

c,<br />

a >∈ borrow ∧ a > 1200)}<br />

3. { < c > | ∀x,<br />

y,<br />

z(<br />

¬ ( < x,<br />

y,<br />

z >∈ branch)<br />

∨ z ≠"<br />

Vancouver"<br />

∨(<br />

∃a,<br />

n(<br />

< x,<br />

a,<br />

c,<br />

n >∈ deposit)))}<br />

ER Diagrams and Relational Schema<br />

Problem 8: Consider that the officials in YVR have decided to organize all the<br />

information related to the airport in a DBMS and you have been hired to design<br />

the database. Your first task is to organize the information about the planes<br />

stationed and maintained at the airport. The relevant information is as follows:<br />

2


* Every airplane has a registration number and is of a specific model.<br />

* The airport accommodates a number of airplane models and each model is<br />

identified by a model number and has a <strong>ca</strong>pacity and a weight.<br />

* A number of technicians work at the airport. You need to store the name, SSN,<br />

address, phone number and salary of each technician.<br />

* Each technician is an expert on one or more plane model(s), and his or her<br />

expertise may overlap with that of other technicians. This information about<br />

technicians must also be recorded.<br />

* Traffic controllers must have an annual medi<strong>ca</strong>l exam. For each traffic<br />

controller you must store the date of the most recent exam.<br />

* All airport employees (including technicians) belong to a union. You must store<br />

the union membership number of each employee. You <strong>ca</strong>n assume that each<br />

employee is uniquely identified by the SSN.<br />

* The airport has a number of tests that are used periodi<strong>ca</strong>lly to ensure that the<br />

planes are still airworthy. Each test has a Federal Aviation Administration<br />

(FAA) test number, a name and a maximum possible score.<br />

* The FAA requires the airport to keep track of each time a given airplane is<br />

tested by a given technician using a given test. For each testing event, the<br />

information needed is the date, the number of hours the technician spent doing<br />

the test, the score the airplane received on the test.<br />

1. Draw an ER diagram for the airport database. Be sure to indi<strong>ca</strong>te the various<br />

attributes of each entity and relationship set. Also specify the key and<br />

participation constraints for each relationship set. Specify any necessary overlap<br />

and covering constraints as well.<br />

2. Assume that the tests on a plane must be conducted by technicians who are<br />

expert on that model. How will you express this constraint in the ER model? If<br />

you <strong>ca</strong>nnot express it, explain briefly.<br />

3. Translate the ER diagram into a relational schema.<br />

3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!