CSCI 5333.2 DBMS Spring 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 both question and answer sheets. 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 a HTTP GET parameter cid: the film category id. It displays all actors appearing in more than four films in the category in a table. For example, for http://.../t2.php?cid=1 it should display the following exactly in the browser. This is because actor NATALIE HOPKINS appears in 6 films in category #1, and so on. Your program may assume that the HTTP parameter is always correct and there is no need to check for errors in the input. Also, it is fine to display an empty page if no result is found. (2) [9 points] Use Armstrong’s axioms and rules to prove that F = {A->B, AC->D, BD->E} implies AC->E (3) [10 points] Consider R(A,B,C,D,E) with the set of FDs: {C->A, A->CE, E->D, BD->E} R is decomposed into R1(A,B,C), R2(A,C,E) and R3(B,D,E). Is the decomposition lossless? Show your reasoning. (4) [12 points] True (T) or False (F) (a) A relation R that is not in BCNF can be in 2NF. (b) It is possible for a relation R(A,B,C,D) to have five candidate keys. (c) In MySQL, when a transaction is committed, the changes are made permanent. (d) In RDB, the ACID properties ensure that all foreign keys must have non-null values. (e) The XPath expression //category[film] retrieves all category elements with a child film element. (f) In MySQL, a stored procedure can call a trigger directly. (5) [25 points] Consider R(A,B,C,D,E,F) with F= {BC->D, C->AE, A->E, F->DE, FE->A} (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. (6) [14 points] Consider the Sakila database again. (a) Create a view s15_fa to include all film names, their category names, ratings of the films, and the numbers of actors in the films. For example, the following query should provide the output shown: mysql> select * -> from s15_fa -> where category = 'Action' -> limit 10; +---------------------+----------+--------+--------------+ | film | category | rating | numberActors | +---------------------+----------+--------+--------------+ | AMADEUS HOLY | Action | PG | 6 | | AMERICAN CIRCUS | Action | R | 5 | | ANTITRUST TOMATOES | Action | NC-17 | 7 | | ARK RIDGEMONT | Action | NC-17 | 3 | | BAREFOOT MANCHURIAN | Action | G | 8 | | BERETS AGENT | Action | PG-13 | 10 | | BRIDE INTRIGUE | Action | G | 1 | | BULL SHAWSHANK | Action | NC-17 | 8 | | CADDYSHACK JEDI | Action | NC-17 | 7 | | CAMPUS REMEMBER | Action | R | 3 | +---------------------+----------+--------+--------------+ 10 rows in set (0.20 sec) (b) Define a stored function: function s15_ff1(category VARCHAR(25), minActors SMALLINT) returns INT The function uses the view s15_fa to return the number of films with minActors or more number of actors in the category. For example: mysql> select s15_ff1('ACTION', 8); +----------------------+ | s15_ff1('ACTION', 8) | +----------------------+ | 14 | +----------------------+ 1 row in set (0.23 sec) This is because there are 14 films in the category ACTION with 8 or more actors.