Solutions. Updated of 7

Similar documents
CSE 544 Principles of Database Management Systems. Magdalena Balazinska Winter 2009 Lecture 4 - Schema Normalization

Functional Dependencies CS 1270

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2009 Lecture 3 - Schema Normalization

Databases Exam. TDA357 (Chalmers), DIT620 (University of Gothenburg) 7 June 2017, 14:00-18:00

CS145 Midterm Examination

Fundamentals of Database Systems

SCHEMA REFINEMENT AND NORMAL FORMS

SOLUTIONS TO THE FINAL EXAMINATION Introduction to Database Design Spring 2011

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSE 444 Midterm Test

[18 marks] Consider the following schema for tracking customers ratings of books for a bookstore website.

CS 461: Database Systems. Final Review. Julia Stoyanovich

BCNF. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong BCNF

CSE 562 Database Systems

The Relational Data Model

TEST EXAM, Summer Semester 2005 SOLUTION

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Database Management

Presentation on Functional Dependencies CS x265

The University of British Columbia

Database Management Systems (Classroom Practice Booklet Solutions)

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 09:30 and 11:30.

CS411 Database Systems. 05: Relational Schema Design Ch , except and

E-R diagrams and database schemas. Functional dependencies. Definition (tuple, attribute, value). A tuple has the form

Examination examples

Introduction to Database Systems. Announcements CSE 444. Review: Closure, Key, Superkey. Decomposition: Schema Design using FD

Name: Database Systems ( 資料庫系統 ) Midterm exam, November 15, 2006

MIDTERM EXAMINATION Spring 2010 CS403- Database Management Systems (Session - 4) Ref No: Time: 60 min Marks: 38

. : B.Sc. (H) Computer Science. Section A is compulsory. Attempt all parts together. Section A. Specialization lattice and Specialization hierarchy

CSE 344 Final Examination

Database Management Systems Paper Solution

Solutions to Final Examination

Example Examination. Allocated Time: 100 minutes Maximum Points: 250

CSIT5300: Advanced Database Systems

Database Constraints and Design

COMP7640 Assignment 2

Homework 6: FDs, NFs and XML (due April 13 th, 2016, 4:00pm, hard-copy in-class please)

Computer Science 304

Chapter 2: Intro to Relational Model

Database Management Systems (Solutions for Vol 1_Classroom Practice Questions)

COMP9311 Week 10 Lecture. DBMS Architecture. DBMS Architecture and Implementation. Database Application Performance

Exercise 9: Normal Forms

Midterm Exam (Version B) CS 122A Spring 2017

Normalization. Murali Mani. What and Why Normalization? To remove potential redundancy in design

CSE 344 Final Examination

Schema Refinement and Normal Forms

Exam II Computer Programming 420 Dr. St. John Lehman College City University of New York 20 November 2001

Databases -Normalization I. (GF Royle, N Spadaccini ) Databases - Normalization I 1 / 24

Homework 3: Relational Database Design Theory (100 points)

Normalization 03. CSE3421 notes

Schema Refinement & Normalization Theory 2. Week 15

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key

Final Examination Computer Science 420 Dr. St. John Lehman College City University of New York 21 May 2002

Chapter 2: Intro to Relational Model

Database Technology Introduction. Heiko Paulheim

McGill April 2009 Final Examination Database Systems COMP 421

Integrity Constraints and Functional Dependency

CS127 Homework #3. Due: October 11th, :59 P.M. Consider the following set of functional dependencies, F, for the schema R(A, B, C, D, E)

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

Relational Design: Characteristics of Well-designed DB

The University of British Columbia Computer Science 304 Practice Final Examination

5 Normalization:Quality of relational designs

CSEP 514 Midterm. Tuesday, Feb. 7, 2017, 5-6:20pm. Question Points Score Total: 150

Exam Actual. Higher Quality. Better Service! QUESTION & ANSWER

DATABASE MANAGEMENT SYSTEM

Intermediate SQL ( )

CS x265 Exam 3 Spring ALL questions 5 points, except question 11 I will not use a source other than my brain on this exam: (please sign)

Chapter 16. Relational Database Design Algorithms. Database Design Approaches. Top-Down Design

Babu Banarasi Das National Institute of Technology and Management

Chapter 1: Introduction

IMPORTANT: Circle the last two letters of your class account:

CHALMERS UNIVERSITY OF TECHNOLOGY Department of Computer Science and Engineering Examination in Databases, TDA357/DIT620 Thursday 27 March 2008, 08:30

A Deeper Look at Data Modeling. Shan-Hung Wu & DataLab CS, NTHU

[12 marks] Consider the following schema for a program that pairs students with mentors who offer career advice.

Database Normalization. (Olav Dæhli 2018)

DKT 122/3 DIGITAL SYSTEM 1

Changes from 3 edition: with

CMU SCS CMU SCS CMU SCS CMU SCS whole nothing but

COSC Dr. Ramon Lawrence. Emp Relation

Answer Key for Exam II Computer Science 420 Dr. St. John Lehman College City University of New York 18 April 2002

This lecture. Databases -Normalization I. Repeating Data. Redundancy. This lecture introduces normal forms, decomposition and normalization.

Relational Database Design (II)

Unit- III (Functional dependencies and Normalization, Relational Data Model and Relational Algebra)

Exam. Question: Total Points: Score:

Typical relationship between entities is ((a,b),(c,d) ) is best represented by one table RS (a,b,c,d)

PLEASE HAND IN. Good Luck! UNIVERSITY OF TORONTO Faculty of Arts and Science. December 2009 Examinations. CSC 343H1F Duration 3 hours.

Assignment #3. CS Spring 2015 Due on Saturday, July 25, 2015, 9 AM For instructions on how to submit your assignment check the course website.

Review. S V T Ma Mo N A S. Mo Ma T

Functional Dependencies and Finding a Minimal Cover

Note that alternative datatypes are possible. Other choices for not null attributes may be acceptable.

Apriori Algorithm. 1 Bread, Milk 2 Bread, Diaper, Beer, Eggs 3 Milk, Diaper, Beer, Coke 4 Bread, Milk, Diaper, Beer 5 Bread, Milk, Diaper, Coke

Exam I Computer Science 420 Dr. St. John Lehman College City University of New York 12 March 2002

CS 474, Spring 2016 Midterm Exam #2

UNIT 3 DATABASE DESIGN

Home Page. Title Page. Page 1 of 14. Go Back. Full Screen. Close. Quit

DATABASE MANAGEMENT SYSTEMS

Design Theory for Relational Databases

CSE 444 Final Exam. August 21, Question 1 / 15. Question 2 / 25. Question 3 / 25. Question 4 / 15. Question 5 / 20.

1.4 Euler Diagram Layout Techniques

Transcription:

CHALMERS UNIVERSITY OF TECHNOLOGY Department of Computer Science and Engineering Examination in Databases, TDA357/DIT620 Tuesday 17 December 2013, 14:00-18:00 Solutions Updated 2014-11-19 1 of 7

Question 1. a) (Here is one suggestion. Several other designs are also accepted. For example, modelling Teacher, Parent and Child as subclasses of 12 p Person.) person number Parent phone number choice parent of person number Nursery applies to Child start date in nursery ISA Section enrolled Enrolled Child assigned to Teacher person number b) N urseries() Sections(nursery, ) nursery N urseries. T eachers(personn umber,, nursery, section) (nursery, section) Sections.(nursery, ) P arents(personn umber,, phonen umber) Children(personN umber,, startdate) EnrolledChildren(personN umber, nursery, section) personn umber Children.personN umber (nursery, section) Sections.(nursery, ) AppliesT o(child, nursery, choice) child Children.personN umber nursery N urseries. P arentof(parent, child) parent P arents.personn umber child Children.personN umber 2 of 7

Question 2. a) In addition to the FDs listed in the question, we also have: 11 p AB -> C AC -> B AD -> B AD -> C BD -> C ABD -> C ACD -> B BCD -> A Superkeys: AD, BD, ABD, ACD, BCD, ABCD Keys: AD, BD b) i) FDs violating BCNF: A->B, B->C, A->C, AB->C, AC->B ii) FDs violating 3NF: B->C, A->C, AB->C c) Decompose R on A->B {A}+ = {ABC} R1(_A,B,C) R2(_A,_D) A -> R1.A Decompose R1 on B->C {B}+ = {BC} R11(_B,C) R12(_A,B) B->R11.B Update reference for R2: A -> R12.A d) (a1,b2,c2,d2) (a2,b1,c1,d3) (a2,b3,c3,d1) 3 of 7

Question 3. a) Of f ices(city, supplement) 9 p Departments(city, d, departmenthead) city Offices.city departmenthead Employees.empId Employees(empId,, salary, dept, city) (city, dept) Departments.(city, d) CREATE TABLE Offices ( city VARCHAR(20) PRIMARY KEY, supplement INT DEFAULT 0, ); CREATE TABLE Departments ( city VARCHAR(20), d VARCHAR(20), departmenthead CHAR(10), PRIMARY KEY (city, d), FOREIGN KEY (city) REFERENCES Offices(city) FOREIGN KEY (departmenthead) REFERENCES Employees(empId) ON DELETE SET NULL ON UPDATE CASCADE, ); CREATE TABLE Employees ( empid CHAR(10) PRIMARY KEY, VARCHAR(30), salary INT, dept VARCHAR(20), city VARCHAR(20), FOREIGN KEY (city, dept) REFERENCES Departments(city, d) ); Several of the solutions we saw used the policy CASCADE instead of SET NULL for the foreign key constraint on attribute departmenthead in table Departments. Consider what would be the consequences of this. The solution shown above would give an error if executed, due to the forward references from the Departments table definition to the Employees table, which hasn t been created yet. This complication was ignored when marking the exam. In practice, we could omit this foreign key constraint when creating the Departments table, and then add this constraint after the Employees table has been created. This can be done using the ALTER TABLE statement, e.g. ALTER TABLE Departments ADD CONSTRAINT departmentrefemployee FOREIGN KEY (departmenthead) REFERENCES Employees(empId) INITIALLY DEFERRED DEFERRABLE; For more information on this, see the section on Deferring Constraint Checking on the website for the course textbook: http://infolab.stanford.edu/~ullman/fcdb/oracle/or-triggers.html 4 of 7

b) CREATE ASSERTION HeadOfOwnDept CHECK ( NOT EXISTS ( SELECT departmenthead JOIN Employees ON departmenthead = empid WHERE d <> dept OR Departments.city <> Employees.city ) ) c) CREATE PROCEDURE Merge ( IN city1 VARCHAR(20), IN dept1 VARCHAR(20), IN city2 VARCHAR(20), IN dept2 VARCHAR(20) ) BEGIN IF ( SELECT COUNT(empId) FROM Employees WHERE city = city1 AND dept = dept1 ) > ( SELECT COUNT(empId) FROM Employees WHERE city = city2 AND dept = dept2 ) THEN UPDATE Departments SET departmenthead = ( SELECT departmenthead WHERE city = city1 AND d = dept1 ) WHERE city = city2 AND dept = dept2; ENDIF; UPDATE Employees SET city = city2, dept = dept2 WHERE city = city1 AND dept = dept1; DELETE WHERE city = city1 AND d = dept1; END; 5 of 7

Question 4. a) 6 p τ (π empid,,salary+supplement (Employees Offices)) b) If we assume that all sales departments have at least one employee: γ city,av G(salary) avgsalary (σ dept= sales (Employees)) If there can be sales departments with no employees, we might want to include those in the result, with 0 as the average. This can be done by forming the union of the relational algebra expression given above with: π city,0 (π city (σ d= sales (Departments)) π city (σ dept= sales (Employees))) Question 5. a) SELECT empid,, salary + supplement AS totalsalary 10 p FROM Employees NATURAL JOIN Offices ORDER BY b) i) SELECT d WHERE city = "London" AND d NOT IN ( SELECT d WHERE city = "Paris" ) ii) ( SELECT d WHERE city = "London" ) EXCEPT ( SELECT d WHERE city = "Paris" ) c) CREATE VIEW SalaryBill AS SELECT city, SUM(salary + supplement) AS amount FROM Employees NATURAL JOIN Offices GROUP BY city 6 of 7

Question 6. a) The result printed by transaction T1 could be different if transaction T1 and T3 are 5 p run concurrently. Good answers will discuss the concept of phantoms (see Example 6.47 in the course textbook) and the schedule of operations that causes different results to be printed. b) i) task 1: 2 task 2: 30 ii) task 1: 4 task 2: 6 iii) It would be better to have an index on city (cost: 420 vs. 480). Question 7. a) Corrected DTD is: 7 p <!DOCTYPE A [ <!ELEMENT A (B*) > <!ELEMENT B (C) > <!ELEMENT C (#PCDATA) > <!ATTLIST A a1 CDATA #REQUIRED > <!ATTLIST B b1 CDATA #REQUIRED b2 CDATA #IMPLIED > <!ATTLIST C c1 CDATA #REQUIRED > ]> b) i) <B b1="b1" b2="15"> <C c1="red">first</c> </B> <B b1="b4" b2="35"> <C c1="red">fourth</c> </B> ii) <C c1="blue">third</c> <C c1="red">fourth</c> c) <Result> { for $b in (doc("exam.xml")//b) order by $b/c/@c1 return <C c1="{$b/c/@c1}"><b b1="{$b/@b1}" /></C> } </Result> 7 of 7