CSCI 5333 DBMS Spring 2018 Final Examination Last Name: First Name: Student Id: Number: Time allowed: two hours. Total score: 100 points. This is a closed book examination but you can bring a cheat sheet. Answer all questions. Turn in the question paper, any answer sheets, the cheat sheet and all rough work. Plan your time well. Academic honesty policy will be followed strictly. Cheating will be pursued vigorously and will result in a failing grade of D or below, a permanent academic record and possibly other more serious penalty. Many questions refer to the Sakila database we have used extensively in lectures and homework. Please refer to the relation schemas in the supplementary sheets to answer these questions.
(1) [24 points] Write a PHP program, t2.php, to accept a HTTP GET parameter fid, the film s id. The program displays the actors appeared in the films, together with the number of films each actor cast in. For example: http://.../t2.php?fid=1 should display the following in the browser. This is because, for example, the film with id 1 has 10 actors, whom appeared in 40 to 19 films. You may assume that there will be no error in the HTTP parameters. Please answer your question in the next page. A skeleton is provided for you below. There is no need to copy the skeleton again in your answer next page. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>csci 5333 DBMS Spring 2018 Final Examination, Question 1</title> </head> <body> <?php // Minimally documented. dbconfit_sakila will make available the // $mysqli object. include('dbconfig_sakila.php'); Your code: write it in the next page. (No need to write the skeleton again in the next page.) $mysqli->close();?> </body> </html>
(1) Answer question (1) here. Write in the back page if necessary.
(2) [28 points] (a) List the ids and names of films with both actors with actor_id 2 and actor_id 95. For example, film_id 47 has actors with ids: 2, 8, 89, 95, 127, 143, 153 and 158. It is the only one with actors with id 2 and 95 respectively. +---------+-----------+ film_id title +---------+-----------+ 47 BABY HALL +---------+-----------+ 1 row in set (0.00 sec) (b) Create a view s18t2 that shows the information about the numbers of times a customer rented a film in the following manner. Note that customer_id 1 rented the flim_id 317 twice. MariaDB [sakila]> select * from s18t2 -> where customer_id = 1 -> and film_id between 300 and 400; +-------------+---------+------------------+ customer_id film_id number of rental +-------------+---------+------------------+ 1 308 1 1 315 1 1 316 1 1 317 2 1 341 1 +-------------+---------+------------------+ 5 rows in set (0.04 sec)
(c) List the film id, title, number of customers rented the film, total number of rentals of the film of all film with id from 1 to 5. You must use the view s18t2. For example, the film AFFAIR PREJUDICE has been rented by 22 different customers. One of these customers rented it twice and thus numrentals is 23. +---------+------------------+--------------+------------+ film_id title numcustomers numrentals +---------+------------------+--------------+------------+ 1 ACADEMY DINOSAUR 23 23 2 ACE GOLDFINGER 7 7 3 ADAPTATION HOLES 12 12 4 AFFAIR PREJUDICE 22 23 5 AFRICAN EGG 12 12 +---------+------------------+--------------+------------+
(d) Define a function MorePopular to check whether one film is more popular than another film with respect to the number of customers rented the films. You must use the view s18t2 in your function. The function has the following prototype: function MorePopular(film_id_1 smallint unsigned, film_id_2 smallint unsigned) returns boolean For example: MariaDB [sakila]> select MorePopular(1,2), MorePopular(1,3), MorePopular(2,3); +------------------+------------------+------------------+ MorePopular(1,2) MorePopular(1,3) MorePopular(2,3) +------------------+------------------+------------------+ 1 1 0 +------------------+------------------+------------------+ This can be explained by: +---------+-------------------------------------+ film_id Number of customers rented the film +---------+-------------------------------------+ 1 23 2 7 3 12 +---------+-------------------------------------+
(3) [6 points] Use Armstrong s axioms and rules to prove that F = {D->CB, B->A, ACD->E} - D->E (4) [14 points] True (T) or False (F) (a) A relation in 2NF but not in 3NF must have more than one candidate keys. (b) There is always one and only one canonical cover for any set of functional dependencies. (c) Assuming that the names of the relations and attributes are correct, there is no syntax error in the following SQL statement: select film_id, count(actor_id) as countactors from film_actor where countactors >=13 group by film_id order by countactors desc; (d) There are three candidate keys in R(A,B,C,D,E) with {A->B, BC->D, D->CA} (e) The XPath expression //author/name returns all <name> elements in an XML document. (f) There is no universally true functional dependency. (g) In MySQL, a trigger can be activated within a transaction.
(5) [8 points] Consider R(A,B,C,D,E) with the set of FDs: {A->BD, BC->E, AB->E, C->B} R is decomposed into R1(A,C), R2(B,C,E) and R3(A,B,D,E). Is the decomposition lossless? Show your reasoning. Write in the back of the page if necessary.
(6) [20 points] Consider R(A,B,C,D,E,F) with F= {B->C, BC->D, C->A, A->CE, AE->F} (a) What are A+, B+, C+, D+, E+ and F+? (b) What are the candidate keys? Show all prime attributes. (c) Give a canonical cover of F. (d) What is the highest normal form (up to BCNF) of R and why? (e) If R is not in BCNF, can you provide a lossless FD preserving decomposition of R into BCNF relations? If yes, show such decomposition. If no, justify your answer.