Sunteți pe pagina 1din 16

University of Ottawa CSI 2132 and 2532 Final Examination Professor(s): Herna L.

. Viktor and Iluju Kiringa 21 April 2012 09:h30-12h30 Duration: 3 hrs Closed book; no aid allowed, except one double-sided letter-size cheat sheet. Answer all questions in ink. Good luck! / Bonne Chance!

Family name:

First name:

Student number:

Circle your section (For CSI3317 students): Section A Section B

There are 6 questions and a total of 100 points. This exam must contain 16 pages, including this cover page. 1 EER Diagram 2 Relational Algebra and Relational Calculus 3 The Relational Model and SQL 4 Normal Forms 5 Physical database design 6 Storage and Indexing Total / 15 / 15 / 15 / 20 / 15 / 20 / 100

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 2 of 16

1 EER Diagram 15 points


SmartGames is a company that develops educational games for kids. Consider the following description of the SmartGames database, which is used to maintain information about all their employees. The employee information is stored in a database with the following relevant specication: For every employee SmartGames record their social insurance number (SIN); their names and the year in which they were hired. SmartGames hires both regular and seasonal employees. For regular employees, we record the year in which they became regular employees. Seasonal employees have an indication of the year in which they can apply for the regular status. Amongst regular employees, there are part-time and full-time employees. Full-time employees have an indication of the year in which they were promoted to full-time employees. Seasonal employees must be expert in a given area, but an area may have zero or more seasonal employees who are expert in it. All the areas of expertise have an identication, and a description. Areas of expertise include, but are not limited to, programming, graphics design, artist, multimedia coordinator, and so on. A full-time employee can advise a seasonal employee on his expertise in a given area. On the other hand, each expertise of a seasonal employee in an area must have a full-time employee advising on it. Each employee must work exactly on one project (which corresponds to a game), and each project may have more than one employees working on it. A full-time employee must supervise the work of an employee on a project. On the other hand, each work of an employee on a project must have exactly one full-time employee supervising it. Draw an EER diagram for the SmartGame employee database setting. Make sure to indicate all the appropriate constraints and state all your assumptions.

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 3 of 16

Draw your EER diagram here.

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 4 of 16

2 Relational Algebra and Relational Calculus 15 points


Consider the following relational schema about the Nursing staff working in Hospitals across rural Ontario.

Nurse(nid : int, nname : string, age : real, salary : real, sid : int) Supervisor (sid : int, rating : real) W orksIn(nid : int, hid : int, hours : real) Hospital(hid : int, hname : string, tid : int) T own(tid : int, tname : string, mayor : string) Part A 4 points Provide the relational algebra expression to display the names and salaries of all nurses who do not work at any hospital.

Part B 5 points Provide the relational algebra expression to display the names of all nurses, younger than 30 years old, who worked at all the hospitals that are based in a town called Campbellford.

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 5 of 16

Part C 3 points Explain, by means of your own example, the main difference between tuple and domain relational calculus.

Part D 3 points expression ensures.

Explain, by means of your own example, what a safe relational calculus

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 6 of 16

3 The Relational Model and SQL 15 points


Consider, again, the following relational schema about the Nursing staff working in Hospitals across rural Ontario.

Nurse(nid : int, nname : string, age : real, salary : real, sid : int) Supervisor (sid : int, rating : real) W orksIn(nid : int, hid : int, hours : real) Hospital(hid : int, hname : string, tid : int) T own(tid : int, tname : string, mayor : string) Part A 3 points Explaining a Query Consider the following query and explain what data it retrieves. SELECT nname FROM Nurse N WHERE NOT EXISTS ( (SELECT FROM WHERE EXCEPT (SELECT FROM WHERE

H.hid Hospital H H.town = Toronto) W.hid WorksIn W N.nid = W.nid)

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 7 of 16

Part B 4 points Explain how views may be used to ensure logical data independence.

Part C 8 points (SQL Queries) 1. Write the following query in SQL: For each Hospital in which more than 100 nurses work, nd the hospital name, and the number of nurses who work in the hospital. (4 points)

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 8 of 16

2. Write the SQL integrity constraint (primary/foreign key, check, assertion or any other) to ensure each one of the following requirements: Every supervisor must also be a nurse. (2 points)

Every nurse must have a supervisor. (2 points)

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 9 of 16

4 Normal Forms 20 points


Consider the following data recorded about contestants in the new BigTeeth TV reality show. This show focuses on conicts between humans and animals with big teeth, such as crocodiles, tigers and lions. You are asked to run a background check on the contestants to determine whether a person has a police record (PR), to double-check his or her employment history (EMP), and so on. You create a table, which records the following information.

Name John Smith John Smith John Smith John Smith Ann Doe Ann Doe Sam Watson

YofB 1980 1980 1979 1979 1975 1975 1981

PRecord Ottawa Ottawa none Toronto none Montreal none

PRDate 12 Sept 11 1 Sept 08 none 1 Dec 06 none 3 Dec 08 none

PRCat Serious Minor none Minor none Serious none

PROutcome Jail Fine none Fine none Jail none

EmpName JollyBouncer JollyBouncer Walmart none Sears none none

EmpComments Fired Fired Good Employee none Resigned none none

A. (8 points) This table may be susceptible to a number of data inconsistencies, due to information redundancy. Explain, by means of your own examples with reference to the BigTeeth data, what potential problems (or anomalies) may occur.

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 10 of 16

B. (4 points) Identify all the functional dependencies, as based on the data in the BigTeeth table.

C. (4 points) Normalize the relation to Boyce Codd Normal Form and show your resultant relations, indicating all primary and foreign keys.

D. (2 points) Determine whether your decomposition is dependency preserving and motivate your answer.

E. (2 points) Determine whether your decomposition is a lossless-join decomposition and motivate your answer.

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 11 of 16

5 Physical database design 15 points


Consider, for the last time, the following relational schema about the Nursing staff working in Hospitals across rural Ontario.

Nurse(nid : int, nname : string, age : real, salary : real, sid : int) Supervisor (sid : int, rating : real) W orksIn(nid : int, hid : int, hours : real) Hospital(hid : int, hname : string, tid : int) T own(tid : int, tname : string, mayor : string) Assume that there are currently no indexes dened on any of the tables. The Nurse relation spans 100 disk pages and the current buffer size is 10. Further, the WorksIn relation spans 20 disk pages. Consider the following query 1.

SELECT N.nname, W.hours FROM Nurse N, WorksIn W WHERE N.salary > 20000 AND N.nid = W.nid AND hours = 100;

A. (5 points) Discuss a scenario where adding indexes may improve the efciency of the query. Motivate your answer by listing two different indexing options to consider.

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 12 of 16

B. (4 points) Explain how the buffer manager processes a read request for a page.

C. (6 points) Having variable-length elds in a record may raise some subtle issues, especially when a record is modied. Discuss three (3) issues that may arise.

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 13 of 16

6 Storage and Indexing 20 points


Part A 10 points (B+ Trees) Consider the following instance of the Sailors relation, as seen in class. sid 7 1 3 5 4 2 6 8 10 9 12 11 sname Sam Joe Sumo Mikey Jil Noam Ann Louis Nathan Liu Wang Jones srating 10.0 2.0 3.0 10.0 2.0 3.0 10.0 2.0 3.0 10.0 2.0 3.0 age 67 71 23 67 71 23 67 71 23 67 71 23

In this question, you must use the bulk loading algorithm to build a B+ tree index on the relation instance above. Use the index organization (alternative 1) where a data entry k is an actual data record with search key value k . Assume an order of 1. Answer the following questions: 1. (4 Points) Show only the rst three steps of the bulk loading algorithm.

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 14 of 16

2. (2 Points) Show the nal tree, after the bulk loading algorithm has been executed.

3. (4 points) Consider the tree you obtained in (2) and show the resulting B+ tree after the deletion (in the order given) of the tuples : 3, Sumo , 3.0, 23 , 5, Mikey , 10.0, 67 , 2, Noam , 3.0, 23 , and 4, Jil , 2.0, 71 .

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 15 of 16

Part B 10 points ((Hash Indexing)) In this question, use the following assumptions and notations: k denotes the data entry corresponding to the search key k . h is the hash function, and for any key k , h(k ) returns the last two bits of the binary representation of the ASCII code of k . Each bucket contains a maximum of 4 data entries. The set of available keys, along with their associated ASCII codes is given in the table below. binary ASCII code 1000001 1000010 1000011 1000100 1000101 1000110 1000111 1001000 1001001 1001010 1001011 1001100 1001101 key A B C D E F G H I J K L M binary ASCII code 1001110 1001111 1010000 1010001 1010010 1010011 1010100 1010101 1010110 1010111 1011000 1011001 1011010 key N O P Q R S T U V W X Y Z

... Contd

CSI 2132 and 2532 Final Examination, 21 April 2012

Page 16 of 16

Consider the following initial hash table.

Global depth 1 0 1

Local depth 1

Show the steps of the extendible hashing algorithm by inserting the following keys from the table above into this table, in this order: D, H, K, M, A, O, P, R, Y, W and V. (Hint: follow the method used in the example of the textbook, where a new gure was introduced only if you must double the directory).

... End of Final Examination

S-ar putea să vă placă și