CSCI 5333.2 DBMS Fall 2015 Final Examination Last Name: ________________ First Name: ____________ Student Id: ________ Number: _________ Version: _______ 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 question paper, answer sheets, cheat sheet and rough work. Write your name and student id in the first page of your answer sheets, and your name in every page. 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! I hereby pledge that I will stay truth to UHCL’s Honor Code. Signature: Date: Many questions refer to the Sakila database we have used extensively in lectures and homework. These table schemas may be useful for answering the questions. CREATE TABLE actor ( actor_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (actor_id), KEY idx_actor_last_name (last_name) )ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE film ( film_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, title VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, release_year YEAR DEFAULT NULL, language_id TINYINT UNSIGNED NOT NULL, original_language_id TINYINT UNSIGNED DEFAULT NULL, rental_duration TINYINT UNSIGNED NOT NULL DEFAULT 3, rental_rate DECIMAL(4,2) NOT NULL DEFAULT 4.99, length SMALLINT UNSIGNED DEFAULT NULL, replacement_cost DECIMAL(5,2) NOT NULL DEFAULT 19.99, rating ENUM('G','PG','PG-13','R','NC-17') DEFAULT 'G', special_features SET('Trailers','Commentaries','Deleted Scenes','Behind the Scenes') DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (film_id), KEY idx_title (title), KEY idx_fk_language_id (language_id), KEY idx_fk_original_language_id (original_language_id), CONSTRAINT fk_film_language FOREIGN KEY (language_id) REFERENCES language (language_id) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT fk_film_language_original FOREIGN KEY (original_language_id) REFERENCES language (language_id) ON DELETE RESTRICT ON UPDATE CASCADE )ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE film_actor ( actor_id SMALLINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (actor_id,film_id), KEY idx_fk_film_id (`film_id`), CONSTRAINT fk_film_actor_actor FOREIGN KEY (actor_id) REFERENCES actor (actor_id) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT fk_film_actor_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE RESTRICT ON UPDATE CASCADE )ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE category ( category_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(25) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (category_id) )ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE film_category ( film_id SMALLINT UNSIGNED NOT NULL, category_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (film_id, category_id), CONSTRAINT fk_film_category_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT fk_film_category_category FOREIGN KEY (category_id) REFERENCES category (category_id) ON DELETE RESTRICT ON UPDATE CASCADE )ENGINE=InnoDB DEFAULT CHARSET=utf8; (1) [30 points] Write a PHP program, t2.php, to accept two HTTP GET parameters aid1 and aid2, both being actor ids. It displays the title and rating of all films with these two actors. For example: http://.../t2.php?aid1=1&aid2=53 It should display the following exactly in the browser. This is because ACADEMY DINOSARY (film_id 1) and WIZARD COLDBLOODED (film_id 980) have both actors 1 and 53. If no result is found, display a message. For example: http://.../t2.php?aid1=1&aid=2 Your program may assume that the HTTP parameters are always correct and there is no need to check for errors in the input. (2) [20 points] Consider the Sakila database again. (a) List the categories the actor with id 4 has appeared in at least three films in the category. List also the film counts in that category. For example: +-------------+-------+ | name | count | +-------------+-------+ | Documentary | 3 | | New | 3 | | Sci-Fi | 3 | +-------------+-------+ 3 rows in set (0.00 sec) Note that actor with id 4 appears in three films in the category Documentary, and so on. (b) Create a view f15_fa to include all category ids, category names, rental rates of all films in the categories, and the numbers of films with the rental rates. For example, the following query should provide the output shown below: mysql> select * -> from f15_fa -> where category_id in (1, 2, 3); +-------------+-----------+-------------+------------+ | category_id | name | rental_rate | film_count | +-------------+-----------+-------------+------------+ | 1 | Action | 0.99 | 28 | | 1 | Action | 2.99 | 19 | | 1 | Action | 4.99 | 17 | | 2 | Animation | 0.99 | 23 | | 2 | Animation | 2.99 | 26 | | 2 | Animation | 4.99 | 17 | | 3 | Children | 0.99 | 21 | | 3 | Children | 2.99 | 21 | | 3 | Children | 4.99 | 18 | +-------------+-----------+-------------+------------+ 9 rows in set (0.04 sec) (c) Define a stored function: function f15_ff1(category_id TINYINT UNSIGNED, rental_rate DECIMAL(4,2)) returns INT The function uses the view f15_fa to return the number of films of the category_id with the rental rates of rental_rate. For example: mysql> select f15_ff1(1, 0.99); +------------------+ | f15_ff1(1, 0.99) | +------------------+ | 28 | +------------------+ 1 row in set (0.03 sec) (3) [7 points] Use Armstrong’s axioms and rules to prove that F = {D->E, AD->C, CD->B, E->A} implies D->B (4) [8 points] Consider R(A,B,C,D,E) with the set of FDs: {AB->C, C->D, DE->A, E->D} R is decomposed into R1(A,B,C), R2(C,D,E) and R3(B,E). Is the decomposition lossless? Show your reasoning. (5) [10 points] True (T) or False (F) (a) By default, MySQL auto commits after the execution of an INSERT statement. (b) It is impossible for a relation R(A,B,C,D) to have 6 candidate keys. (c) If a relation R is not in 3NF, it is also not in BCNF. (d) No non-trivial functional dependency is universal true for every application. (e) Triggers in MySQL are based on an event-driven programming model. (6) [25 points] Consider R(A,B,C,D,E,F) with F= {AB->C, C->D, DE->F, CD->E, E->FB} (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.