COMP302. Database Systems

Similar documents
EXAMINATIONS 2009 END-YEAR. COMP302 / SWEN304 Database Systems / Database System Engineering. Appendix

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

Question 1. SQL and Relational Algebra [25 marks] Question 2. Enhanced Entity Relationship Data Model [25 marks]

SQL: The Query Language Part 1. Relational Query Languages

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

EXAMINATIONS 2013 MID-YEAR SWEN 432 ADVANCED DATABASE DESIGN AND IMPLEMENTATION

The appendix contains information about the Classic Models database. Place your answers on the examination paper and any additional paper used.

Database Management Systems Paper Solution

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

1) Introduction to SQL

SQL Data Definition Language

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Bachelor in Information Technology (BIT) O Term-End Examination

Draw A Relational Schema And Diagram The Functional Dependencies In The Relation >>>CLICK HERE<<<

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture

The University Of New South Wales. Final Exam November 2006 COMP9311. Database Systems

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

DATABASE MANAGEMENT SYSTEMS

Basic SQL. Basic SQL. Basic SQL

CS348: INTRODUCTION TO DATABASE MANAGEMENT (Winter, 2011) FINAL EXAMINATION

A subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select,

Database Systems, CSCI Exam #2 Thursday November 4, 2010 at 2 pm

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

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

Midterm 2: CS186, Spring 2015

EE221 Databases Practicals Manual

Examination paper for TDT4145 Data Modelling and Database Systems

Total No. of Questions :09] [Total No. of Pages : 02. II/IV B.Tech. DEGREE EXAMINATIONS, NOV/DEC Second Semester CSE/IT DBMS

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Database Management

CS2300: File Structures and Introduction to Database Systems

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

D.K.M COLLEGE FOR WOMEN(AUTONOMOUS),VELLORE DATABASE MANAGEMENT SYSTEM QUESTION BANK

Principles of Data Management

VIEW OTHER QUESTION PAPERS

Part II Relational Databases Data as Tables

CSE 444, Winter 2011, Midterm Examination 9 February 2011

1.3. Joins Introduction Access across relations Miniworld approximation Pointing mechanism

CMSC 461 Final Exam Study Guide

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

Solutions to Final Examination

Data about data is database Select correct option: True False Partially True None of the Above

CSE344 Final Exam Winter 2017

Birkbeck. (University of London) BSc/FD EXAMINATION. Department of Computer Science and Information Systems. Database Management (COIY028H6)

GUJARAT TECHNOLOGICAL UNIVERSITY

SQL (Structured Query Language)

Exam. Question: Total Points: Score:

SQL. Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior

McGill April 2009 Final Examination Database Systems COMP 421

L Information Systems for Engineers. Final exam. ETH Zurich, Autumn Semester 2017 Friday

CSE 444 Midterm Exam

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

CSE 444 Midterm Test

Slides by: Ms. Shree Jaswal

Babu Banarasi Das National Institute of Technology and Management

Assignment Session : July-March

CSCB20 Week 3. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

EECS 647: Introduction to Database Systems

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

2.9 Table Creation. CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... )

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment

Midterm Exam (Version B) CS 122A Spring 2017

CSCB20 Week 4. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

CS/B.Tech/CSE/New/SEM-6/CS-601/2013 DATABASE MANAGEMENENT SYSTEM. Time Allotted : 3 Hours Full Marks : 70

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

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

SQL: Data Definition Language

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

6 February 2014 CSE-3421M Test #1 w/ answers p. 1 of 14. CSE-3421M Test #1. Design

ACS-3902 Fall Ron McFadyen 3D21 Slides are based on chapter 5 (7 th edition) (chapter 3 in 6 th edition)

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Northern India Engineering College, New Delhi Question Bank Database Management System. B. Tech. Mechanical & Automation Engineering V Semester

Midterm Exam #1 Version A CS 122A Winter 2017

ARTICLE RELATIONAL ALGEBRA

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

Chapter 3: Introduction to SQL

SQL DATA DEFINITION LANGUAGE

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

Introduction to SQL. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

Unit 1 - Chapter 4,5

The Entity-Relationship Model (ER Model) - Part 2

Database Management

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #4: SQL---Part 2

CS 4320/5320 Homework 2

SQL: DDL. John Ortiz Cs.utsa.edu

QQ Group

CS 461: Database Systems. Final Review. Julia Stoyanovich

The University of British Columbia

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

Schema And Draw The Dependency Diagram

NJIT Department of Computer Science PhD Qualifying Exam on CS 631: DATA MANAGEMENT SYSTEMS DESIGN. Summer 2012

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

Final Exam. December 5th, :00-4:00. CS425 - Database Organization Results

Midterm Exam ANSWER KEY

Transcription:

EXAMINATIONS 2006 MID-YEAR COMP 302 Database Systems Time allowed: Instructions: 3 Hours Answer all questions. Make sure that your answers are clear and to the point. Calculators and printed foreign language dictionaries are allowed. No reference material is allowed. There are 180 marks on the exam. Marks are shown for each question as a whole and also for their parts. CONTENTS: Question 1. Database Basics [25 marks] Question 2. SQL and Relational Algebra [26 marks] Question 3. Enhanced Entity Relationship Data Model [30 marks] Question 4. Mapping EER to Relational Data Model [33 marks] Question 5. Functional Dependencies and Normalization [31 marks] Question 6. Query Optimisation [13 marks] Question 7. Transaction Processing [22 marks] Appendices: A. SQL Reference B. Musicians Database Schema 1

Question 1. Database Basics [25 marks] a) [5 marks] What is a database and what are its main features? b) [7 marks] What are the tasks of a Database Management System? c) [4 marks] What is a relational database schema (the schema of a whole relational database)? 2

d) [4 marks] What is a relation schema key? List the properties of a relation schema key. e) [5 marks] What is a foreign key? List the properties of a foreign key. 3

Question 2. SQL and Relational Algebra [26 marks] Consider the Musicians database schema given below. create table Musician ( MusicianId smallint primary key, Mus_Name varchar (15) not null, Telephone varchar (15), Type varchar (15) not null create table Instrument ( InstrumentId smallint primary key, Inst_Name varchar (15) not null, Musical_Key varchar (10) not null create table Played_By ( MusicianId smallint not null references Musician, InstrumentId smallint not null references Instrument, primary key (MusicianId, InstrumentId) create table Album ( AlbumId smallint primary key, Alb_Title varchar (15) not null, Format varchar (5), Producer smallint not null references Musician(MusicianId) create table Song ( AlbumId smallint not null references Album, Song_No smallint not null, Song_Title varchar (15) not null, primary key (AlbumId, Song_No) create table Performed_By( MusicianId smallint not null references Musician, AlbumId smallint not null, Song_No smallint not null, primary key (MusicianId, AlbumId, Song_No), foreign key (AlbumId, Song_No) references Song 4

a) [23 marks] Write the following SQL queries on the Musicians database given above: i. [3 marks] Retrieve MusicianId and Mus_Name of musicians whose Type is singer. ii. [4 marks] Retrieve MusicianId and Mus_Name of musicians who produced at least one Album with a Format CD. iii. [5 marks] Retrieve MusicianId and Mus_Name of all musicians who did not perform any song. 5

iv. [11 marks] Retrieve MusicianId and Mus_Name of all musicians who performed the largest number of songs. Note: In SQL, if a nested query returns a single attribute and a single tuple, the query result will be treated as a single scalar value. Unlike SQL, Relational Algebra expressions always produce sets of tuples at outputs. Hint: You may find it useful to do this query in a stepwise way. b) [3 marks] Use relational algebra to write the following query: Retrieve MusicianId and Mus_Name of musicians whose Type is singer. 6

(Spare Page for extra working) 7

Question 3. Enhanced Entity Relationship Data Model [30 marks] In this question you will be asked to draw EER diagrams of two external views of the Musicians database defined in Question 2 of this examination. Recall that external views express views of different users on possibly overlapping parts of the same mini world (universe of discourse - UOD). Use the EER notation we introduced in lectures. If you use a different notation, define it clearly in your answer. a) [18 marks] Map the Musicians relational database schema to the entity relationship data model by drawing an EER diagram. State any assumptions you make. Note: There is a copy of the Musicians database schema in Appendix B. 8

b) [12 marks] Draw the EER diagram of another external view of the musicians universe of discourse, described as follows: Musicians can be classified as: Singers, Instrument players, Conductors, or Producers. Each musician belongs to at least one of these classes, but can belong to more than one. A producer has an association with albums: Each album is produced by exactly one producer. A producer may be responsible for the production of many albums, but there may exist producers without any album. An instrument player has an association with instruments: Each instrument player plays at least one instrument. Each instrument may be played by many instrument players, but there may be instruments that are not played by any instrument player. In your answer, show entity and relationship types, relationship type constraints and the classification relationship only. Avoid showing any attributes. 9

Question 4. Mapping EER to Relational Data Model [33 marks] In this question you will be asked to map a number of EER diagrams into relational database schemas (S, I ), where S is a set of relation schemas, and I is a set of referential integrity constraints. The EER diagrams will contain only symbols for entity and relationship types, and relationship constraints. Attributes will be given separately in the form with entity type keys underlined, or Represent your relation schema in the form Entity_Type_Name (Attribute 1,, Attribute n ), Relationship_Type_Name (Attribute 1,, Attribute n ). N(R, K), where R is the set of attributes and K is the set of keys of the relation schema with the name N. Indicate if any foreign key has to be not null. a) [7.5 marks] Map the following ER diagram into a relational database schema. PROGRAMMER N USES N PROG_LANGUAGE PROGRAMMER(ProgrammerId, Prog_Name) USES(Skill_Level) PROG_LANGUAGE(LanguageId, Lang_Name) 10

b) [4.5 marks] Map the following ER diagram into a relational database schema. EMPLOYEE 1 HAS N DEPENDENT EMPLOYEE(EmployeeId, Emp_Name) HAS( ) DEPENDENT(DepName, Age) 11

c) [9 marks] Map the following ER diagram into a relational database schema. Include all constraints you think should be satisfied. STUDENT d UNDERGRADUATE HONOURS POSTGRADUATE STUDENT(StudentId, Stud_Name) UNDERGRADUATE(NoOfPts) HONOURS(Class) POSTGRADUATE(Program) 12

d) [12 marks] Map the following ER diagram into a relational database schema. Include all constraints you think should be satisfied. help recipient N N ENROLLED N TUTOR STUDENT COURSE 1 1 N CLASSREP help giver STUDENT(StudentId, Stud_Name, NoOfPts) COURSE(CourseId, Cour_Name) ENROLLED(InTermPts) CLASSREP( ) TUTOR( ) 13

Question 5. Functional Dependencies and Normalization [31 marks] a) [8 marks] Express the following real world facts using functional dependencies: i. [2 marks] A musical album has exactly one producer (but the same producer may produce many albums). ii. [3 marks] Each song in an album is performed by at most one singer. iii. [3 marks] A singer sings at most one song in an album. b) [5 marks] Let a set of functional dependencies F 2 = {AB C, DEG H, A B, DG H } be given. Transform the set F 2 into a new set of fd s G 2, where each fd is left reduced (ie has no redundant attribute on its left hand side). c) [8 marks] Let a set of left reduced functional dependencies F 3 = {AB C, C D, C C, AB D, CE G, DE G } be given. Transform the set F 3 into a new, non redundant set of fd s G 3. 14

d) [3 marks] Let a set of left reduced and non redundant functional dependencies F 4 = {A B, A C, A D, B E, B G, GH I } be given. Use the set F 4 to produce a set of relation schemes that are at least in the third normal form. (In your answer, use notation N(R, K), where N is the relation schema name, R is the set of attributes, and K is the set of keys.) e) [7 marks] Let a universal relation schema (U, F ) be given, where U = {A, B, C, D, E, G } and F = {AG C, C D, E D }. Suppose that starting from (U, F ) the following set of BCNF relation schemas is produced: S = {N 1 ({A, G, C}, {AG}), N 2 ({C, D }, {C}), N 3 ({D, E }, {E })} If you consider that S is a lossless join decomposition of (U, F ) explain why it is. If you consider that S is not a lossless join decomposition of (U, F ), explain why it is not, and transform it into a new set of relation schemas S that is a BCNF and lossless join decomposition of (U, F ). 15

(Spare Page for extra working) 16

Question 6. Query Optimisation [13 marks] Consider the Musicians database schema given in Question 2 and Appendix B. Draw the heuristic optimization tree that corresponds to the SQL query: SELECT MusicianId, Mus_Name, Song_Title FROM (Musician NATURAL JOIN Performed_By NATURAL JOIN Song) WHERE Type = singer ; 17

Question 7. Transaction Processing [22 marks] a) [4 marks] List the names of four transaction anomalies we discussed in lectures. b) [4 marks] Define the two-phase locking protocol. c) [4 marks] What is the isolation level Read Committed and which transaction anomaly does it prevent? 18

d) [5 marks] Consider a concurrent (interleaved) execution of two transactions in Figure 7.1 below. Show in the space provided for the answer how two-phase locking protocol will prevent this transaction anomaly. T i m e T 1 read_item(x) X = X N write_item(x) T 2 read_item(x) X = X + M write_item(x) Figure 7.1 19

e) [5 marks] Figure 7.2 shows two transactions in a dead lock state. Describe how the conservative two-phase locking protocol will prevent dead lock, and show a corresponding diagram. T i m e T 1 lock_exclusive_item(x) //lock acquired lock_exclusive_item(y) //has to wait T 2 lock_exclusive_item(y) //lock acquired lock_exclusive_item(x) //has to wait Figure 7.2 ***************** 20 end

APPENDIX A Simplified PostgreSQL documentation: CREATE TABLE CREATE TABLE table_name ( { column_name data_type [ DEFAULT default_expr ] [ column_constraint [,... ] ] table_constraint } [,... ] ) where column_constraint is: [ CONSTRAINT constraint_name ] { NOT NULL NULL UNIQUE PRIMARY KEY CHECK (expression) REFERENCES reftable [ ( refcolumn ) ] [ ON DELETE action ] [ ON UPDATE action ] } table_constraint is: [ CONSTRAINT constraint_name ] { UNIQUE ( column_name [,... ] ) PRIMARY KEY ( column_name [,... ] ) CHECK ( expression ) FOREIGN KEY ( column_name [,... ] ) REFERENCES reftable [ ( refcolumn [,... ] ) ] [ ON DELETE action ] [ ON UPDATE action ] } and action is one of RESTRICT, CASCADE, SET NULL, or SET DEFAULT SELECT SELECT [ ALL DISTINCT ] * expression [ AS output_name ] [,...] [ FROM from_item [,...] ] [ WHERE condition ] [ GROUP BY expression [,...] ] [ HAVING condition [,...] ] [ { UNION INTERSECT EXCEPT } [ ALL ] select ] [ ORDER BY expression [ ASC DESC USING operator ] [,...] ] [ FOR UPDATE [ OF tablename [,...] ] ] where from_item can be: [ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias_list ) ] ] ( select ) [ AS ] alias [ ( column_alias_list ) ] from_item [ NATURAL ] [ join_type ] JOIN from_item [ ON join_condition USING ( join_column_list ) ] and join_type can be: INNER LEFT [ OUTER ] RIGHT [ OUTER ] FULL [ OUTER ] CROSS For INNER (the default) and OUTER join types, exactly one of NATURAL, ON join_condition, or USING ( join_column_list ) must appear. For CROSS JOIN, none of these items may appear. CREATE VIEW CREATE VIEW view [ ( column name list ) ] AS SELECT query Some Data Types integer, int, smallint character[n], char[n], character varying[n], varchar[n], varchar numeric, numeric[precision], numeric[precision, scale], real, double boolean, date, Note: [ xxx ] means xxx is optional, { xxx yyy } means xxx or yyy. 21 Appendix

APPENDIX B The Musicians Database Schema create table Musician ( MusicianId smallint primary key, Mus_Name varchar (15) not null, Telephone varchar (15), Type varchar (15) not null create table Instrument ( InstrumentId smallint primary key, Inst_Name varchar (15) not null, Musical_Key varchar (10) not null create table Played_By ( MusicianId smallint not null references Musician, InstrumentId smallint not null references Instrument, primary key (MusicianId, InstrumentId) create table Album ( AlbumId smallint primary key, Alb_Title varchar (15) not null, Format varchar (5), Producer smallint not null references Musician(MusicianId) create table Song ( AlbumId smallint not null references Album, Song_No smallint not null, Song_Title varchar (15) not null, primary key (AlbumId, Song_No) create table Performed_By( MusicianId smallint not null references Musician, AlbumId smallint not null, Song_No smallint not null, primary key (MusicianId, AlbumId, Song_No), foreign key (AlbumId, Song_No) references Song 22 Appendix