CSCI 5333 DBMS Fall 2017 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) [25 points] Write a PHP program, t2.php, to accept a HTTP GET parameter cid, the customer id. The program displays the categories and the numbers of rented films by the customer in these categories. For example: http://.../t2.php?cid=3 should display the following in the browser. This is because, for example, customer with id 3 has rented four films from the category Action, and so on. 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 Fall 2017 Final Examination, Question 1</title> </head> <body> <?php include('dbconfig_sakila.php'); Your code: write it in the next page. $mysqli->close();?> </body> </html>
(1) Answer question (1) here. Write in the back page if necessary.
(2) [21 points] (a) Create a view f17t2 to provide film information that can be used as below. For example: MariaDB [sakila]> select * -> from f17t2 -> where length >= 100 -> and `number of actors` >12; +---------+------------------+--------+------------------+ film_id title length number of actors +---------+------------------+--------+------------------+ 146 CHITTY LOCK 107 13 188 CRAZY HOME 136 13 249 DRACULA CRYSTAL 176 13 508 LAMBS CINCINATTI 144 15 606 MUMMY CREATURES 160 13 +---------+------------------+--------+------------------+ 5 rows in set (0.03 sec)) (b) Using the view defined in (a), provide the SQL statement to show the top four categories with the most numbers of films with at least 10 actors in the following manners. For example: +-----------+------------+ category filmcounts +-----------+------------+ Comedy 5 Sports 5 Animation 4 Action 4 +-----------+------------+ 4 rows in set (0.02 sec)
(c) Define a stored function s17a to accept two arguments, category_id and min_actors. The function returns the number of films in the category with the id category_id and has at least min_actors number of actors. You must use the view f17t2 of (a) to define your function. For example: MariaDB [sakila]> select f17t2f(5,10); +--------------+ f17t2f(5,10) +--------------+ 5 +--------------+ This can be explained by: MariaDB [sakila]> select fc.film_id, count(distinct fa.actor_id) as count -> from film_category fc, film_actor fa -> where fc.film_id = fa.film_id -> and fc.category_id = 5 -> group by fc.film_id -> having count >= 10; +---------+-------+ film_id count +---------+-------+ 188 13 410 10 529 12 680 11 858 11 +---------+-------+ 5 rows in set (0.00 sec)
(3) [7 points] Use Armstrong s axioms and rules to prove that F = {C->A, AB->D, BD->E} - BC->E (4) [14 points] True (T) or False (F) (a) The number of function dependencies (FD) of a minimal cover of a set of FD F cannot be more than the number of FDs of a canonical cover of F. (b) A trigger in MySQL can be called directly within a stored procedure but not a stored function. (c) In MySQL, the HAVING clause of a SELECT statement cannot come before the GROUP BY clause. (d) The XPath expression //film/title returns all <title> elements that is a child element of a <film> element in the document. (e) A relation in 3NF form but not in BCNF must have more than one candidate keys. (f) In MySQL, it is possible to have a transaction that is atomic but not consistent. (g) The relation R(A,B,C,D,E) must have at least one candidate key.
(5) [8 points] Consider R(A,B,C,D,E) with the set of FDs: {B->AE, AB->E, BD->C, C->AB} R is decomposed into R1(A,B), R2(B,C,D) and R3(B,E). Is the decomposition lossless? Show your reasoning. Write in the back of the page if necessary.
(6) [25 points] Consider R(A,B,C,D,E,F) with F= {A->D, BC->D, AD->E, A-> F, BCD->E, E->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.