Birkbeck (University of London) BSc/FD EXAMINATION Department of Computer Science and Information Systems Database Management (COIY028H6) CREDIT VALUE: 15 credits Date of examination: Monday 9th June 2014 Duration of paper: (14:30 16:30) There are five questions on this paper. Answer only four of the five questions. Each question carries 25 marks in total. The paper is not prior-disclosed. The use of electronic calculators is not permitted. COIY028H6 Page 1 of 6 c Birkbeck College 2014
1. (a) The relational model requires that all relations be in first normal form. Explain what this means. Recall that the entity-relationship (ER) model allows for multi-valued attributes. Explain why these are incompatible with the first normal form requirement of the relational model. Given an entity type with a multivalued attribute in an ER model, how would you represent this in the relational model? (e) SQL allows the use of (table) aliases (also know as tuple variables) in a query. How are aliases declared in SQL? Describe one situation in which the use of aliases is essential, and one situation in which their use is helpful. Explain the differences between (i) a superkey and a key, and (ii) a superkey and a functional dependency. Consider an example relation schema Reviews, with schema(reviews) = {Book, Rating, Author} on which a single functional dependency Book Author holds. Let a relation over Reviews be given by Book Rating Author Amsterdam Good McEwan Amsterdam Excellent McEwan Disgrace Good Coetzee Disgrace Average Coetzee If we decompose Reviews into {Book, Rating} and {Rating, Author} and then perform the natural join of the decomposed relations, we get back two tuples that were not in the original relation. i. What is the name given to this type of join or decomposition and why is it considered undesirable? (3 marks) ii. In general, what condition on decomposing a relation schema will prevent the above situation arising? (2 marks) When SQL is used along with a language such as PHP, there is a possibility of using placeholders in the SQL. Explain the purpose of placeholders. Name the two different kinds of placeholder, demonstrating their use with examples. COIY028H6 Page 2 of 6 c Birkbeck College 2014
2. (a) Using the entity-relationship (ER) model, assume that we want to model the rates relationship type between users of Amazon and products available for sale on Amazon. So a rates relationship between user u and product p represents the fact that user u has rated product p on Amazon. What multiplicity and participation constraints should be specified for the rates relationship type? Justify your answers. When creating a table definition for a table T, say, in SQL, one can specify constraints such as (i) primary key (A 1,..., A n ) (ii) foreign key (A 1,..., A n ) references R where A 1,..., A n refer to column names and R denotes a table name. Explain precisely what conditions the DBMS will enforce as a result of each of the above two constraints. SQL provides a number of different ways in which a normal (inner) join operation (i.e., not a natural join or outer join) can be specified. Describe three different syntactic constructs in SQL which specify join operations. Let U be a relation schema with schema(u) = CT HRSG, where the meaning of the attributes is as follows: C (course), T (teacher), H (hour), R (room), S (student) and G (grade). Let F be the following a set of functional dependencies (FDs) over U: C T, i.e. a course has one teacher. HR C, i.e. a room can only have one course at any time. HT R, i.e. a teacher can only be in one room at any time. CS G, i.e. a student has one grade per course. HS R, i.e. a student can only be in one room at any time. i. Compute the closure of the set of attributes CH, explaining each step of the computation. (2 marks) ii. Find a key for U, explaining why it is a key. (2 marks) iii. Now produce a decomposition of U into Third Normal Form, explaining each step you used to arrive at the decomposition. (6 marks) COIY028H6 Page 3 of 6 c Birkbeck College 2014
3. (a) Consider a relational database schema in which there are four relations, Part, Supplier, Project and Supply. The schemas of the relations are as follows: schema(part) = { PNum, PName }, schema(supplier) = { SNum, SName }, schema(project) = { JNum, JName }, schema(supply) = { SNum, PNum, JNum, Qty }. Primary key attributes have been underlined above. Draw an entity-relationship diagram which models the same information and from which the above relation schemas might have been derived. (10 marks) In SQL, we can group a sequence of statements into a transaction. Transactions can end their execution in one of two ways. Give the names for the two operations which end a transaction and explain how the database is affected by each. The relational model allows the use of NULL values to represent unknown or inapplicable values. While this feature is very useful, it also causes some complications. Describe three situations in which the use of NULL values either complicates the syntax of SQL or makes query processing more involved. Compare Boyce-Codd Normal Form and Third Normal Form in terms of their relative advantages and disadvantages. COIY028H6 Page 4 of 6 c Birkbeck College 2014
4. (a) Assume that a database contains a relation Sales with schema(sales) = {Invoice, Day, Month, Amount}. Explain what the query SELECT Month, SUM(Amount) FROM Sales GROUP BY Month HAVING COUNT(Invoice) < 10; returns when executed on the database. Consider the following relation over the schema Films, representing information about films and actors: Title Year Genre StarName Star Wars 1977 SciFi Carrie Fisher Star Wars 1977 SciFi Harrison Ford Raiders... 1981 Action Harrison Ford Raiders... 1981 Adventure Harrison Ford When Harry... 1989 Comedy Carrie Fisher Assume that Title Year is the only functional dependency which holds on the schema Films. i. What is the only key for Films? (2 marks) ii. Give an example of a redundancy problem for Films. (2 marks) iii. Give an example of an insertion anomaly for Films, explaining why it is an anomaly. (2 marks) iv. Decompose Films into relation schemas in Boyce-Codd Normal Form, explaining how you arrived at the decomposition. (4 marks) SQL transactions are meant to be atomic. Explain what the term atomic means, and demonstrate, using an example, a problem which would arise if a transaction were not atomic. Name five features provided by object-relational database systems which are not available in (pure) relational database systems. COIY028H6 Page 5 of 6 c Birkbeck College 2014
5. (a) Database systems provide three levels of abstraction which support data independence. Describe the three levels and the extent to which they can guarantee data independence. Assume that we have a relation over schema Supply(Supplier, Part, Quantity) and a view defined as follows: CREATE VIEW bigsuppliers AS SELECT Supplier, Part FROM Supply WHERE Quantity > 1000; A user issues the following SQL command: INSERT INTO bigsuppliers VALUES ( ABC Ltd, Axle ); What condition(s) must be true in order for this command to execute without generating an error message? What is the result of the command, assuming that it executes successfully? Give a short explanation of what is meant by each of the following terms: i. embedded SQL ii. dirty read iii. left outer join iv. correlated subquery v. dependency preservation (10 marks) Assume that you are using PHP to issue a query to a relational database such as MySQL, and that the answer of the query is returned in the variable $result. Explain how you would print out all the attribute values in each row of the result. You can use a fragment of code to illustrate your answer if you wish. COIY028H6 Page 6 of 6 c Birkbeck College 2014