The University of British Columbia



Similar documents
LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Announcements. SQL is hot! Facebook. Goal. Database Design Process. IT420: Database Management and Organization. Normalization (Chapter 3)

Schema Design and Normal Forms Sid Name Level Rating Wage Hours

SQL DDL. DBS Database Systems Designing Relational Databases. Inclusion Constraints. Key Constraints

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

Databases What the Specification Says

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Functional Dependencies

Database Constraints and Design

6.830 Lecture PS1 Due Next Time (Tuesday!) Lab 1 Out today start early! Relational Model Continued, and Schema Design and Normalization

Functional Dependencies and Finding a Minimal Cover

SAMPLE FINAL EXAMINATION SPRING SESSION 2015

CS143 Notes: Normalization Theory

The class slides, your notes, and the sample problem that we worked in class may be helpful for reference.

Databases -Normalization III. (N Spadaccini 2010 and W Liu 2012) Databases - Normalization III 1 / 31

Why Is This Important? Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) Example (Contd.)

Exercise 1: Relational Model

Limitations of E-R Designs. Relational Normalization Theory. Redundancy and Other Problems. Redundancy. Anomalies. Example

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

DATABASE NORMALIZATION

Relational Database Design: FD s & BCNF

Database Design Final Project

Design of Relational Database Schemas

Fundamentals of Database System

normalisation Goals: Suppose we have a db scheme: is it good? define precise notions of the qualities of a relational database scheme

Lecture Notes on Database Normalization

Chapter 7: Relational Database Design

Introduction Decomposition Simple Synthesis Bernstein Synthesis and Beyond. 6. Normalization. Stéphane Bressan. January 28, 2015

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Schema Refinement and Normalization

How To Find Out What A Key Is In A Database Engine

IT2305 Database Systems I (Compulsory)

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

SQL NULL s, Constraints, Triggers

Introduction to Databases

There are five fields or columns, with names and types as shown above.

Week 11: Normal Forms. Logical Database Design. Normal Forms and Normalization. Examples of Redundancy

BCA. Database Management System

Relational Databases

Chapter 5: Logical Database Design and the Relational Model Part 2: Normalization. Introduction to Normalization. Normal Forms.

Database Design and Normalization

Functional Dependencies and Normalization

Relational Database Design

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

We can express this in decimal notation (in contrast to the underline notation we have been using) as follows: b + 90c = c + 10b

MCQs~Databases~Relational Model and Normalization

Entity/Relationship Modelling. Database Systems Lecture 4 Natasha Alechina

Database Sample Examination

Chapter 10 Functional Dependencies and Normalization for Relational Databases

IT2304: Database Systems 1 (DBS 1)

The process of database development. Logical model: relational DBMS. Relation

The Relational Data Model: Structure

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

Data Analysis 1. SET08104 Database Systems. Napier University

THE BCS PROFESSIONAL EXAMINATION Diploma. October 2004 EXAMINERS REPORT. Database Systems

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

Database Design and Normal Forms

Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

Chapter 7: Relational Database Design

CIS Information and Database Systems I. Course Syllabus Spring 2015

Chapter 10. Functional Dependencies and Normalization for Relational Databases


Lecture 6. SQL, Logical DB Design

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 5: Normalization II; Database design case studies. September 26, 2005

RELATIONAL DATABASE DESIGN

Normalization of database model. Pazmany Peter Catholic University 2005 Zoltan Fodroczi

Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases

Normalisation 1. Chapter 4.1 V4.0. Napier University

Accentuate the Negative: Homework Examples from ACE

SAT Math Facts & Formulas Review Quiz

CMU - SCS / Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013

14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Chapter 10. Functional Dependencies and Normalization for Relational Databases. Copyright 2007 Ramez Elmasri and Shamkant B.

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

City University of Hong Kong. Information on a Course offered by Department of Computer Science with effect from Semester A in 2014 / 2015

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

Database Design Process. Databases - Entity-Relationship Modelling. Requirements Analysis. Database Design

CSE 444 Midterm Test

Data Modeling. Database Systems: The Complete Book Ch ,

Relational Algebra and SQL

Schema Refinement, Functional Dependencies, Normalization

Review of Fundamental Mathematics

Limitations of DB Design Processes

Answer Key. UNIVERSITY OF CALIFORNIA College of Engineering Department of EECS, Computer Science Division

CMPT 354 Database Systems. Simon Fraser University Summer Instructor: Oliver Schulte

The Relational Data Model and Relational Database Constraints

Introduction to Database Systems. Normalization

CSIS 202: Introduction to Computer Science Spring term Midterm Exam

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

6.2 Permutations continued

I. Introduction to Taxation

The Entity-Relationship Model

DIVISIBILITY AND GREATEST COMMON DIVISORS

Transcription:

The University of British Columbia Computer Science 304 Midterm Examination October 31, 2005 Time: 50 minutes Total marks: 50 Instructor: Rachel Pottinger Name ANSWER KEY (PRINT) (Last) (First) Signature This examination has 6 pages. Check that you have a complete paper. MARKS This is a closed book exam. No books or other material may be used. Answer all the questions on this paper. Give very short but precise answers. State any assumptions you make Work fast and do the easy questions first. Leave some time to review your exam at the end. The marks for each question are given in {}. Use this to manage your time. Do not spend on a question more minutes than the marks assigned to it. 1. 2. 3. 4. Total Good Luck

1. {8 marks, 1 mark per question} Circle only one answer per question no points will be taken off for incorrect answers (i.e., you might as well guess): a. SQL is a procedural language. SQL is declarative you specify what you want, not how you want it. The query optimizer will come up with a declarative query execution plan b. We use ER diagrams to logically model concepts. ER diagrams are used for conceptual modeling, not logical modeling. This is on the reminder of where we are in the introduction slide for most units. c. This diagram is an example of a relationship with a many to one cardinality ratio. This is one to many. See ER diagram slides. Note that this was initially graded incorrectly, but this is the correct answer. d. Every query that can be expressed in relational algebra can be expressed as a safe query in domain relational calculus; the converse is also true. The catch is that the queries must be safe, otherwise domain relational calculus is more expressive. See slides on DRC. e. AB C, D E, E C is a minimal cover for the set of functional dependencies AB C, D E, AB E, E C.. There s no way to derive AB E from the first list of dependencies f. An update anomaly is when it is not possible to store certain information unless some other, unrelated, information is stored as well.. An update anomaly is if one copy of such repeated data is updated, an inconsistency is created unless all copies are similarly update. What is described is an insertion anomaly (see textbook page 607) g. Given the table R(a,b,c) (i.e., a and b form the primary key of R), the following is a valid table definition. CREATE TABLE S ( a INTEGER, d INTEGER, e INTEGER, PRIMARY KEY (d), FOREIGN KEY (a) references R). A foreign key must reference all of a key in this case it must reference a,b h. In ER diagrams, aggregation may be used instead of a ternary relation if we need to impose additional constraints. See slides or page 45 in the book Page 2

2. {14 marks} Consider the schema R = (A, B, C, D, E, F) together with the functional dependencies: A B DE F B C a. {10 marks} Is R(A, B, C, D, E, F) in BCNF? If so, say why. If not, decompose this relation into BCNF using the algorithm we covered in class and in the book; circle all relations in your final decomposition. We begin by finding all of the (candidate) keys. The easiest way to do this is to calculate the closures. When in doubt, look at all closures. But we can tell that the only interesting closures are those that appear on the left hand side of some rule, so we ll start there: A+ = ABC B+ = BC DE+ = DEF Thus we can see that A must be part of any key (since it s the only way to derive A), and that DE and E must similarly be part of any key. Since ADE+ = ABCDEF, ADE is a key, and in fact, the only key of R. For a relation S to be in BCNF, each non trivial functional dependency of the form X y (where X is a set of attributes, and y is a single attribute), it must be the case that X is a superkey of S. Therefore, since ADE is the only key, all of the given functional dependencies violate BCNF, and we must decompose R. We arbitrarily choose to begin decomposition on A B. We decompose into R1(AB), R2(A,C,D,E,F) Now we determine if we need to continue decomposing R1 and R2. Because R1 is a 2 valued relation, we know it is in BCNF, so we turn to R2. DE F violates BCNF because in R DE+ = DEF. Therefore, projected onto R2, DE+ = DEF, and DE is not a key of R2. DE F is therefore a violation of BCNF, and we must decompose again. We get R3(D,E,F), and R4(A,C,D,E). Are they in BCNF? R3 is in BCNF because DE is a key, so it is not a BCNF violation, and there are no other non trivial functional dependencies on R3. For R4, however, we know from above that A+ = ABC. Projected onto R4, this means that A+ = AC. Which means both that the functional dependency A C holds on R4 and that A is not a key of R4. So we decompose to yield R5(A,C), R6(A,D,E). R5 is in BCNF since it only has 2 attributes, and since we know that the closure of A yields nothing in R6 other than itself, and similarly for the closure of DE, R6 is in BCNF. Therefore, the final answer is: R1(A,B), R3(D,E,F), R5(A,C), R6(A,D,E) b. {4 marks} Is R(A, B, C, D, E, F) in 3NF? If so, why. If not, list all violations of 3NF in R. B, C, and F are part of no keys, nor, as illustrated above, are A, DE, or B part of a superkey. Therefore, all three violate 3NF. Page 3

3. {14 marks} Look at the following partially constructed ER diagram about pet stores, which includes the following: Merchandise can be of many types, including animals and other types Animals can be cats, dogs, or other species Merchandise can be sold, which involves the merchandise, an employee, and a customer Animals are taken care of by some employee Animals live in cages a. {6 marks} Make the following changes/additions to the ER diagram: i. Add in the constraint that each animal must be taken care of by some employee ii. Add in the date that an employee takes care of an animal. Note that you should make it possible for an employee to take care of an animal on more than one date iii. Add in the specification that each animal lives in exactly one cage See the above diagram. Note that we could not add an attribute for date to Takes Care of, because each relationship must be uniquely determined by its attributes, so we must add an entity for it. See Slide 22 on Chapter 2: Conceptual design. Page 4

b. {6 marks} Transform the ER diagram, including the modifications you made in part a, into a relational schema using the methods discussed in class/the book. Note that this ER diagram has been carefully chosen so that there is one right choice for each transformation. State any assumptions that you make but your assumptions cannot contradict the facts given. Output: i. Your resulting schema in the form Relation(attribute1,, attributen), where you underline each relation s primary key. Customer (cid) Employee(esin) Merchandise(mid, weight) AnimalLivesIn(Amid, Name, days, cage#) (combined because it s many to one) Cage(cage_num) Cat(catid, HairLength) Dog(dogid, Breed) Feeding(Date) Sale(cid, esin, mid) TakesCareOf(sin,animal id,date) Note that because each Is a relation is not total, and each superclass has a relationship on it, we must use the method where we create one table for each of Merchandise, Animal (which is combined with Lives in since it s a many to one relationship), Dog, and Cat. See slides 15 & 16 in second part of Relational model. ii. For any foreign keys that you have identify the table in which they appear, and write how they would appear in SQL DDL note you only have to declare the foreign key constraint in SQL DDL not the rest of the question. In Sale: Foreign Key (mid) references Merchandise Foreign Key (esin) references Employee Foreign Key (cid) references Customer In Animal: Foreign Key(id) references Merchandise In Cat: Foreign Key(catid) references Animal (We took to Merchandise, but should be Animal only) In Dog: Foreign Key(dogid) references Animal In TakesCareOf: Foreign Key(sin) references Employee Foreign Key(animal id) references Animal Foreign Key(date) references Feeding c. {2 marks} Answer the following question about your relational schema: are there any constraints that cannot be modeled without using assertions? If so, which constraint(s)? If not, why not? We cannot model that every animal has to be taken care of by some employee without assertions. See slides 10 & 11 in second part of Relational Model Page 5

4. {14 marks} Consider a relational database about real estate that is maintained by a real estate agency. The database consists of the following table (where the primary keys are underlined): House (id, asking_price, address, postal_code, baths, beds, sqft, sellerid) Seller(id, name, home_phone, e mail, agentid) Buyer(id, name, home_phone, e mail, agentid) Agent(id, name, mobile_phone, e mail) Sold(house_id, buyer_id, sale date, selling_price) Where House gives information about a house for sale, seller gives information about the sellers of a house, Buyer gives information about (prospective) home buyers, Agent gives information about agents (who can act on behalf of either the buyer or the seller), and sold gives information about the sale of a particular home including the price at which the home actually sold, which may be different from the asking price. For all questions, note that this is just a right way to answer the queries, there may be others a. {7 marks} answer the following questions in relational algebra: i. What are the id, addresses, asking_price, and selling_price of all houses that sold for less than the asking price? π house.id,address, asking_price, selling_price (House House.id = Sold.id Sold.selling_price < House.asking_priceSold ) ii. What are names of all of (prospective) buyers who have not bought a house? Each name should appear only once. π name (Buyer id=buyer_id (π buyer_id (ρ(id buyer_id)buyer) π buyer_id Sold) Note that because relational algebra treats all values as sets, we don t need to make any special arrangement to ensure that each name appears only once. Note that unless you were careful you missed non buyers with same name as buyers b. {7 marks} Answer the following questions in SQL: i. For each postal code in which there were at least three houses sold, find the postal code and the average selling price of houses in that postal code. Select H.postal_code, avg(selling_price) as AVG_Price From House H, Sold S Where H.id = S.house_id Group by H.postal_code Having Count(house_id) >= 3 Note: the count must be in the having clause, and the comparison must be in the where ii. Find the addresses and asking prices of all houses that have at least 3 bedrooms and two bathrooms that have not sold. Each address, asking price pair should appear only once. Select DISTINCT H.address, H.asking_prices, FROM House H, Where H.beds > 2 and H.baths > 1 and NOT EXISTS ( Select house_id From Sold S Where S.house_id = H.id ) Page 6