Practice questions recommended before the final examination

Similar documents
School of Computing and Information Technology. Examination Paper Autumn Session 2018

School of Computing and Information Technology Session: Spring CSCI835 Database Systems (Bridging Subject) Sample class test 23 July 2018

School of Computing and Information Technology. Examination Paper Autumn 2016

School of Computing and Information Technology. Examination Paper Autumn Session 2017

CSCI315 Database Design and Implementation Singapore Assignment 2 11 January 2018

CSCI235/CSCI835 Database Systems Assignment 1 5 August 2018

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

GUJARAT TECHNOLOGICAL UNIVERSITY

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

CSIT115/CSIT815 Data Management and Security Assignment 2

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

CSIT115/CSIT815 Data Management and Security Assignment 1 5 March 2018

Database Systems Relational Model. A.R. Hurson 323 CS Building

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

CS 338 Functional Dependencies

DATABASE MANAGEMENT SYSTEM

Essay Question: Explain 4 different means by which constrains are represented in the Conceptual Data Model (CDM).

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

Relational Model. CS 377: Database Systems

The Relational Model

CSE 444, Winter 2011, Midterm Examination 9 February 2011

CS 348 Introduction to Database Management Assignment 2

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

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

CT13 DATABASE MANAGEMENT SYSTEMS DEC 2015

Object Modeling. Entity-Relationship (ER) diagrams (1976) Object Modelling Technique (OMT) diagrams (1991)

MCA (Revised) Term-End Examination June, 2013 MCS-023 : DATABASE MANAGEMENT SYSTEMS. Time : 3 hours Maximum Marks : 100 (VVeightage 75%)

Transforming ER to Relational Schema

SQL Interview Questions

COSC Assignment 2

Class Information. Textbooks. Grading. Final Project. Grading. CS 440: Database Management Systems. Instructor:

Schema Refinement: Dependencies and Normal Forms

CS 461: Database Systems. Final Review. Julia Stoyanovich

2011 DATABASE MANAGEMENT SYSTEM


Midterm Exam #1 (Version B) CS 122A Spring 2018

Schema Refinement: Dependencies and Normal Forms

Mapping ER Diagrams to. Relations (Cont d) Mapping ER Diagrams to. Exercise. Relations. Mapping ER Diagrams to Relations (Cont d) Exercise

Midterm Exam (Version B) CS 122A Spring 2017

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

Database Management Systems Paper Solution

Informal Design Guidelines for Relational Databases

Functional Dependencies and Normalization for Relational Databases Design & Analysis of Database Systems

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1

Name :. Roll No. :... Invigilator s Signature : DATABASE MANAGEMENT SYSTEM

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

CMP-3440 Database Systems

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

Logical Database Design. ICT285 Databases: Topic 06

Tutorial 2: Relational Modelling

Multiple-Choice. 1. Which of the following is equivalent to a table? (3 pts.) a. record b. relation c. relationship d. constraint e.

Chapter 1: Introduction

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

MCA (Revised) Term-End Examination December,

Entity-Relationship Model &

Schema Refinement: Dependencies and Normal Forms

CSE 444 Midterm Exam

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

DATABASE MANAGEMENT SYSTEMS

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

Babu Banarasi Das National Institute of Technology and Management

Database Management

Course Title: Introduction to Database Management System Course Code: CSIT116 Course Level: UG Course Credits:04 L T P/ S SW/F W

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

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, normal forms. University of Edinburgh - January 25 th, 2016

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

Multiple-Choice. 3. When you want to see all of the awards, even those not yet granted to a student, replace JOIN in the following

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

1 Prepared By Heena Patel (Asst. Prof)

CS2255 DATABASE MANAGEMENT SYSTEMS QUESTION BANK UNIT I

Information Systems (Informationssysteme)

V. Database Design CS448/ How to obtain a good relational database schema

CSCI 5333 DBMS Fall 2018 Mid-Term Examination. Last Name: First Name: Student Id:

The University of Nottingham

E-R Model. Hi! Here in this lecture we are going to discuss about the E-R Model.

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

Transaction Isolation Level in ODI

Objective. The goal is to review material covered in Chapters 1-5. Do the following questions from the book.

DBS Assignment I. 1. With necessary examples, explain any four major disadvantages of keeping organizational information in a file-processing system.

CSE 344 Final Examination

How to design a database

Database Systems. Answers

Course Outline Faculty of Computing and Information Technology

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

NOTE: DO NOT REMOVE THIS EXAM PAPER FROM THE EXAM VENUE

BSc (Hons) Software Engineering. BSc (Hons) Computer Science with Network Security. Examinations for / Semester 2 & 2017 / Semester 1

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

We shall represent a relation as a table with columns and rows. Each column of the table has a name, or attribute. Each row is called a tuple.

EECS-3421a: Test #1 Design

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

Chapter 2: Entity-Relationship Model

Distributed Database Systems By Syed Bakhtawar Shah Abid Lecturer in Computer Science

Database Management Systems (CS 601) Assignments

Chapter 10. Normalization. Chapter Outline. Chapter Outline(contd.)

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

Oracle Database 10g: Introduction to SQL

Database Systems Concepts *

Part VIII Transactions, Integrity and Triggers

Database Design and the E-R Model (7.4, )

VU Mobile Powered by S NO Group All Rights Reserved S NO Group 2013

Transcription:

CSCI235 Database Systems, Spring 2017 Practice questions recommended before the final examination Conceptual modelling Task 1 Read the following specification of a sample database domain. A construction company would like to implement an extensible line drawing system. The A company needs a database to store information about technical drawings. A technical drawing consists of elementary and complex graphical components. Elementary graphical components include sections of straight lines, points, and arcs. Complex graphical components can be created through a composition of elementary and other complex graphical components. A section of straight line is described by (x, y) coordinates of its endpoints. A point is described by (x, y) coordinates. An arc is described by (x,y) coordinates of a center point and (x,y) coordinates of a start point and end point. Each elementary graphical component is additionally described by a width and colour. It is possible to create two or more sections of straight lines with the identical (x, y) coordinates of the endpoints. It is a case when the sections of straight lines perfectly overlap. It is also possible to create any number of perfectly overlapping elementary or complex graphical components. A technical drawing is additionally described by a unique name, date when it has been created, all dates when it has been changed together with a short description of what has been changed, and full name of a person who created a drawing. Of course, information about a technical drawing must include information about the positions of all its elementary and complex components in the drawing. The database must also contain information about the internal structures of all complex graphical components that can be used by a designer. Each time a new complex graphical component is created its structure (definition) must be stored in the database. Design a conceptual schema for the database, which will keep information about the technical drawings. Use the notation of simplified UML class diagrams explained during the lecture classes and applied for conceptual modeling in the assignments. Remember to determine the multiplicities of associations, identifiers of classes of objects, multivalued, optional and derived attributes (if any). Make sure that a schema of your database does not contain redundancies and it correctly represents all information that should be

included in the database. You are allowed to apply any design methodology, which is the most convenient for you. Task 2 Consider the following conceptual schema. ORDER order# ID delivery-date Consists-of line-number 0..1 LINE item quantity 1..* Submits FREQUENT-CUSTOMER discount CUSTOMER cname ID1 address ID1 phone ID2 points (t,e) ORDINARY-CUSTOMER The objective of this task is to extend the schema with time dependent information. Your task is to extend the schema in the following ways. (1) Ordinary customers become frequent customers and the opposite. We would like to record a date when an ordinary customer became a frequent customer and the opposite. Remember, that customer may change its status from ordinary to frequent and the opposite many times and we would like to record all such changes. (2) Customers collect points. We would like to record all modifications of the total number of points collected by the customers together with the dates when the modifications have happened. (3) Items are included into many orders. We would like to record information when an item has been included into an order. Note, that item can be included into many orders. Redraw the conceptual schema after all modifications and list all transformations applied.

Task 3 A conceptual schema given below represents a "point-in-time" database domain of software companies that employ administration staff and programmers. The programmers work on implementation of software modules. Software modules consist of functions. EMPLOYEE e# ID1 fname lname dob salary * Has value * ATTRIBUTE name ID (t-e) ADMIN duties[1..*] PROGRAMMER Works-on 1..* when-started 1..* INVOLVEMENT when-compl[0..1] MODULE name ID1 version ID1 fspec Includes fname 0..1 FUNCTION plang source-code Extend the conceptual schema given above with the following time dependent information. (1) We would like to record information about the new attributes added and removed from the descriptions of employees. We would like to record information when an attribute has been added and when it has been removed. (2) We would like to record how duties of administration staff members change in time. (3) We would to record how salaries of programmers change in time. Note, that we do not want to record information how salaries of administration staff members change in time. (4) We would like to record information about new functions added to the modules and when such additions have happened. In all cases listed above apply a formal method of transformation of "point-in-time" design into a design with time dependent information.

Task 4 We would like to design a database to store information collected from the various types of questionnaires filled by the customers at a large supermarket. A questionnaire is described by a unique code, title, short description and date when it has been designed. A questionnaire consists of three types of graphical elements: paragraphs, text fields, and groups of checkboxes. A paragraph is a section of text that consists of individual statements. Customers cannot change paragraphs. A text field consist of a short text and a rectangle area following it where the customer can to express their opinions, write comments, answer questions, etc. Each text field is preceded by a short text. A sample text field looks as follows. What is your opinion about our grocery section? A short fragment of text common to the entire group precedes a group of check boxes. A customer is allowed to check none or more checkboxes within a group. Each check box is also preceded by a short text. A sample group of check boxes is given below. The best of cheese corner: Colby yellow Cottage white Brie mushroom Rotten blue Socks A form consists of sections and each section consists of any number of paragraphs, text fields and groups of checkboxes. A section has a title, which is unique for a questionnaire. The customers fill in the questionnaires. An entire process of submission of the questionnaire is completely anonymous. Each physical copy of a questionnaire has a unique barcode and when it is scanned at a counter a unique date and time is recorded for the questionnaire. Later on information from a questionnaire is entered into the database. Use a notation of simplified UML classes of objects to design a conceptual schema of the database that contains information about the questionnaires filled by the customers.

Task 5 A conceptual schema given below represents a "point-in-time" database domain of transportation companies, which owns a number of vehicles and employs a number of drivers and mechanics. Drivers drive vehicles and mechanic repair vehicles. DRIVER license# ID fname lname category Drives 1..* VEHICLE registration# ID make capacity Repairs 1..* MECHANIC e# ID fname ID lname ID salary (t-e) 1..* Works-at OTHER TRUCK capacity CAR passenger# COMPANY cname ID address Extend the conceptual schema above with the following temporal information. (1) Mechanics repair many vehicles. We would like to record temporal information about repaired vehicles. (2) Mechanics join and leave companies. We would like to record temporal information about all mechanics who ever worked for transportation companies. Note, that a mechanic can join and leave the same company many times. (3) Drivers improve their categories. We would like to record temporal information about all improvements to the categories of drivers. (4) Some vehicles are too old to be repaired. We would like to record temporal information about the vehicles which are no longer in use. Extend the conceptual schema given above such that it correctly represents the additional information listed above. Redraw the conceptual schema after all modifications.

Task 6 A company frequently runs the questionnaires among its employees. Each questionnaire has a unique name and it consists of several components. A fixed component of each questionnaire includes a name of questionnaire, employee number, first and last name of an employee, department an employee belongs to, and position occupied by an employee. A variable component of a questionnaire has a name, which is unique within the questionnaire and it consists of a number of check boxes to be ticked by an employee and text associated with each check box. Each questionnaire consists of one fixed component and one or more variable components. Design a conceptual schema of a database that can be used to store information collected from the employees during many questionnaires. A graphical form of a sample questionnaire is given below. Questionnaire Name Employee#: First name: Department: Option-1-1 Option-1-2 Option-1-n Last name: Position: Section-name-1 Option-2-1 Option-2-2 Option-2-m Section-name-2 Option-k-1 Option-k-2 Option-k-p Section-name-k

Task 7 The objective of this task is to design a database that can be used to store information about the database designs created with the notation of Entity-Relationship diagrams. Assume, that the Entity-Relationhip diagrams consists of the following structural components: entity type, relationship, multiplicity of relationshsip (e.g. one-to-one, oneto-many, one-to-zero-or-many, etc) attribute describing entity type or relationship, identifier of entity type, weak entity type, and identifying relationship. Create a conceptual schema of a database that contains information about Entity- Relationship diagrams.

Database triggers Task 8 Processing of the following CREATE TABLE statements created the relational tables POSITION and APPLIES. CREATE TABLE POSITION( /* Advertised positions */ pnumber NUMBER(8) NOT NULL, /* Position number */ title VARCHAR(30) NOT NULL, /* Position title */ salary NUMBER(9,2) NOT NULL, /* Salary */ ename VARCHAR(100) NOT NULL, /* Employer name */ CONSTRAINT POSITION_pkey PRIMARY KEY ( pnumber ) ); CREATE TABLE APPLIES( anumber NUMBER(6) NOT NULL, /* Applicant number */ pnumber NUMBER(8) NOT NULL, /* Position number */ appdate DATE NOT NULL, /* Application date */ CONSTRAINT APPLIES_pkey PRIMARY KEY ( anumber, pnumber ), CONSTRAINT APPLIES_fkey FOREIGN KEY ( pnumber ) REFERENCES POSITION ( pnumber ) ON DELETE CASCADE); A relational table POSITION contains information about the employment opportunities (positions) offered by the employers. A relational table APPLIES contains information about the applications for the positions described in a relational table POSITION. Next, the relational tables POSITION and APPLIES have been filled with data. Write SQL script that performs the following actions: (1) First, the script must change a structure of the database such that it would be possible to add to the database information about the total number of applications for each position. Note, that minimal amount of new information must be added to the database. It means that after all structural modification the relational tables are still in BCNF. (2) Next, the script must update the database such that information about the total number of applications for each position is permanently recorded in the database. (3) Next, the script must implement a row database trigger that enforce correctness of information about the total number of applications whenever information about a new application is added to the database or information about existing application is deleted from the database. (4) Finally, the script must comprehensively test a trigger implemented in the previous step.

Task 9 SQL script listed below creates a small relational database that contains information about the skills (a relational table SKILL), about the skills possessed by the applicants (a relational table SPOSSESSED), and about the applicants applying for the positions (a relational table APPLIES). CREATE TABLE SKILL( sname VARCHAR(20) NOT NULL, /* Skill name */ description VARCHAR(2000) NOT NULL, /* Skill description */ CONSTRAINT SNEEDED_PKEY PRIMARY KEY (sname) ); CREATE TABLE SPOSSESSED( aname VARCHAR(30)) NOT NULL, /* Applicant name */ sname VARCHAR(20) NOT NULL, /* Skill name */ level NUMBER(3) NOT NULL, /* Skill level */ CONSTRAINT SPOSSESSED_PKEY PRIMARY KEY (aname, sname) ), CONSTRAINT SPOSSESSED_FKEY FOREIGN KEY (sname) REFERENCES SKILL(sname) ); CREATE TABLE APPLIES( aname VARCHAR(30) NOT NULL, /* Applicant name */ pname VARCHAR(50) NOT NULL, /* Position name */ CONSTRAINT APPLIES_PKEY PRIMARY KEY (aname, pname) ); (1) Implement SQL script that extends the database with information about the total number of applications submitted by each applicant. Your script must change the structures of the database and it must store correct information in the extended database. Note, that you must consider the optimal restructuring of the database and such that after restructuring all relational tables are at least in BCNF. (2) Implement the database triggers that automatically update information about the total number of applications submitted by each applicant.

Task 10 SQL script dbcreate.sql contains CREATE TABLE statements listed below. CREATE TABLE PROJECT( code VARCHAR(100) NOT NULL, title VARCHAR(500) NOT NULL, budget NUMBER(9,2) NOT NULL, started DATE NOT NULL, ended DATE NULL, CONSTRAINT PROJECT_PKEY PRIMARY KEY(code) ); CREATE TABLE EMPLOYEE( e# NUMBER(9) NOT NULL, fname VARCHAR(30) NOT NULL, lname VARCHAR(30) NOT NULL, dob DATE NOT NULL, code VARCHAR(100) NULL, CONSTRAINT EMPLOYEE_PKEY PRIMARY KEY(e#), CONSTRAINT EMPLOYEE_FKEY FOREIGN KEY(code) REFERENCES PROJECT(code) ); Write SQL script that performs the following actions: (1) (2) (3) First, the script must add to the database information about the length of a project each employee is involved in. Note, that each employee works on no more than one project. The script must perform a structural modification of the database and then for each employee it must update information about the length of a project an employee is involved in. Note, that minimal amount of new information must be added to the database. Next, the script must implement a row database trigger that enforce correctness of information about the length of a project an employee is involved in whenever information about a new employee added to the database. Finally the script must comprehensively test a trigger implemented in a step (2).

Task 11 A database contains information about the projects and employees assigned to the projects. An employee can be assigned to no more than one project, and may be assigned to no projects at all. The database has been created with CREATE TABLE statements listed below. CREATE TABLE PROJECT( code VARCHAR(100) NOT NULL, title VARCHAR(500) NOT NULL, budget NUMBER(9,2) NOT NULL, started DATE NOT NULL, ended DATE NULL, CONSTRAINT PROJECT_PKEY PRIMARY KEY(code) ); CREATE TABLE EMPLOYEE( e# NUMBER(9) NOT NULL, fname VARCHAR(30) NOT NULL, lname VARCHAR(30) NOT NULL, dob DATE NOT NULL, code VARCHAR(100) NULL, CONSTRAINT EMPLOYEE_PKEY PRIMARY KEY(e#), CONSTRAINT EMPLOYEE_FKEY FOREIGN KEY(code) REFERENCES PROJECT(code) ); A database has been loaded with data. It happens, that from time to time some projects are cancelled. A relational table CANCELLED contains the codes and titles of cancelled projects. A relational table CANCELLED has been created with the following CREATE TABLE statement. CREATE TABLE CANCELLED( code VARCHAR(100) NOT NULL, title VARCHAR(500) NULL, CONSTRAINT CANCELLED_PKEY PRIMARY KEY(code) ); Whenever a project is cancelled then a part of its description including the values of attributes code and title is copied from a relational table PROJECT into a relational table CANCELLED. All employees who worked on the project are disconnected from the cancelled project and remain not connected to any project until they get their new assignment. At the end, a complete description of the project is removed from a relational table PROJECT. Cancelling of a project is triggered by an insertion of a row into a relational table CANCELLED. For example, the following statement supposed to cancel a project 'P007'. INSERT INTO CANCELLED VALUES('P007', NULL); Implement a row database trigger that cancels a project. Note, that you are not allowed to change the definitions of the relational tables PROJECT and EMPLOYEE.

Task 12 A database has been created with CREATE TABLE statements listed below. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE EMPLOYER( /* Employers */ ename VARCHAR(100) NOT NULL, /* Employer name */ city VARCHAR(30) NOT NULL, /* City */ state VARCHAR(20) NOT NULL, /* State */ phone NUMBER(10) NOT NULL, /* Phone number */ fax NUMBER(10), /* Fax number */ email VARCHAR(50), /* E-mail address */ web VARCHAR(50), /* Web site address */ CONSTRAINT EMPLOYER_pkey PRIMARY KEY ( ename ) ); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE POSITION( /* Advertised positions */ pnumber NUMBER(8) NOT NULL, /* Position number */ title VARCHAR(30) NOT NULL, /* Position title */ salary NUMBER(9,2) NOT NULL, /* Salary */ extras VARCHAR(50), /* Extras */ bonus NUMBER(9,2), /* End of year bonus */ specification VARCHAR(2000) NOT NULL, /* Specification */ ename VARCHAR(100) NOT NULL, /* Employer name */ CONSTRAINT POSITION_pkey PRIMARY KEY ( pnumber ), CONSTRAINT POSITION_fkey FOREIGN KEY ( ename) REFERENCES EMPLOYER( ename ) ); Use a technique of database triggers to implement the following consistency constraint: The positions that have the same titles and that are offered by the same employer must have the same salaries. Your solution must consider all data manipulations that could violate the consistency constraint listed above. Implement SQL statements that comprehensively test the triggers implemented in the previous step, i.e. each implemented database trigger must "fire" at least one time during the testing. Implement SQL statements that drop the triggers after testing.

Database normalization Task 13 Consider the relational schemas given below and the respective sets of functional dependencies valid in the schemas. For each one of the relational schemas, determine the highest normal form, which is valid for a schema. Justify your answer. Justification must include the derivations of minimal keys from the functional dependencies and testing the validity of all normal forms (2NF, 3NF, BCNF) against the relational schemas, minimal keys, and functional dependencies. If a schema is not in BCNF, then decompose it into a minimum number of schemas so that each one of them is in BCNF. Justify your answer. A correct guess without the comprehensive justifications scores no marks! (1) PLAYER( pnum, team, name, position, address ) pnum -> team, name, position, address team -> address (2) ROOM( bnum, rnum, area, type ) bnum, rnum -> area, type rnum -> area, type (3) CONNECTION( bnum, rnum, ip ) bnum, rnum -> ip ip -> rnum (4) COURSE (student#, course#, lecturer, department) course#, student# lecturer course#, student# department lecturer course (5) Product (s#, city, p#, quantity, status) s# city s# status city status s#, p# quantity s#, p# city s#, p# status

The schemas of relational tables, specifications of primary, candidate, foreign keys and check constraints are given below. CREATE TABLE Owner ( phone# NUMBER(10), /* owner's phone number */ name VARCHAR2(50), /* owner's name */ city VARCHAR2(30), /* city of owner's address */ street VARCHAR2(30), /* street name of owner's address */ streetnum NUMBER(4), /* street number of owner's address */ CONSTRAINT Owner_PK PRIMARY KEY (phone#), CONSTRAINT Owner_CK1 UNIQUE (city, street, streetnum) ); CREATE TABLE Property ( p# NUMBER(8), /* Property number */ city VARCHAR2(30), /* city of its address */ street VARCHAR2(30), /* street name of its address */ streetnum NUMBER(4), /* street number of its address */ phone# NUMBER(10), /* owner's phone number */ price NUMBER(10,2), /* price asked by the owner */ CONSTRAINT Property_PK PRIMARY KEY (p#), CONSTRAINT Property_CK1 UNIQUE (city, street, streetnum), CONSTRAINT Property_FK FOREIGN KEY (phone#) REFERENCES Owner(phone#) ); CREATE TABLE Buyer ( phone# NUMBER(10), /* buyer's phone number */ name VARCHAR2(50), /* buyer's name */ city VARCHAR2(30), /* city of buyer's address */ street VARCHAR2(30), /* street name of buyer's address */ streetnum NUMBER(4), /* street number of buyer's address */ CONSTRAINT Buyer_PK PRIMARY KEY (phone#), CONSTRAINT Buyer_CK1 UNIQUE (city, street, streetnum) ); CREATE TABLE Preference ( phone# NUMBER(10), /* phone number of buyer */ city VARCHAR2(30), /* buyer preferred city */ street VARCHAR2(30), /* buyer preferred street */ maxprice NUMBER(10,2), /* maximum price */ minprice NUMBER(10,2), /* minimum price */ when DATE, /* date of preference recorded */ CONSTRAINT Preference_PK PRIMARY KEY (phone#, when), CONSTRAINT Preference_FK FOREIGN KEY (phone#) REFERENCES Buyer (phone#)

); CREATE TABLE Inspection ( phone# NUMBER(10), /* buyer's phone number */ p# NUMBER(8), /* property number */ when DATE, /* inspection date */ CONSTRAINT Inspection_PK PRIMARY KEY (phone#, p#, when), CONSTRAINT Inspection_FK1 FOREIGN KEY (phone#) REFERENCES Buyer(phone#), CONSTRAINT Inspection_FK2 FOREIGN KEY (p#) REFERENCES Property(p#) );

Advanced SQL programing Task 14: Subquery factoring The following questions refer to the relational tables created in page 14-15. Implement the following questions by using WITH clause. 1. Find the owners phone numbers and names that live in their own properties. Hint: An owner s address is the same as his/her property s address. An address consists of street number, street and city. 2. Find the properties street numbers, street names and cities that satisfy the preferences of a buyer whose phone number is 1234567. 3. Find inspection information include buyer s phone number, property s address that appointed on 20/10/2017 between 10:00-11:00 AM. Task 15: Multitable insert statement The follow question refers to the relational tables created in page 14-15. Two relational tables have been created by using the follow statements. CREATE TABLE ActiveBuyer ( phone# NUMBER(10), /* buyer's phone number */ totalinspections NUMBER(2), /* Total inspections */ CONSTRAINT ACTIVEBUYER_PK PRIMARY KEY (phone#), CONSTRAINT ACTIVEBUYER_FK FOREIGN KEY (phone#) REFERENCES Buyer (phone#) ); CREATE TABLE OtherBuyer ( phone# NUMBER(10), /* buyer's phone number */ totalinspections NUMBER(2), /* Total inspections */ CONSTRAINT ACTIVEBUYER_PK PRIMARY KEY (phone#), CONSTRAINT ACTIVEBUYER_FK FOREIGN KEY (phone#) REFERENCES Buyer (phone#) ); Use multitable insert statement to insert data into a table ActiveBuyer when a buyer has inspected properties at least three times in the last 30 days. Otherwise insert data into a table OtherBuyer.

Task 16: MERGE statement The follow question refers to the relational tables created in page 14-15. A relational table has been created by using the follow SQL statement. CREATE TABLE PreferredProperty ( p# NUMBER(8), /* Property number */ city VARCHAR2(30), /* city of its address */ street VARCHAR2(30), /* street name of its address */ streetnum NUMBER(4), /* street number of its address */ phone# NUMBER(10), /* owner's phone number */ price NUMBER(10,2), /* price asked by the owner */ CONSTRAINT Property_PK PRIMARY KEY (p#), CONSTRAINT Property_CK1 UNIQUE (city, street, streetnum), CONSTRAINT Property_FK FOREIGN KEY (phone#) REFERENCES Owner(phone#) ); Suppose some data have been stored in the relational table PreferredProperty. Use MERGE statement to insert or update data in the table PreferredProperty from the property that preferred by buyers. Hint: A preferred property is a property that located in the city and street, and its price (between maximum and minimum prices) preferred by any buyers. Task 17: Hierarchical query A relational table has been created by using the follow SQL statement. CREATE TABLE Skill ( sname VARCHAR2(50), /* Skill name */ description VARCHAR2(200), /* Description of skill */ required VARCHAR2(50), /* Required by skill */ CONSTRAINT Skill_PK PRIMARY KEY (sname), CONSTRAINT Skill_FK FOREIGN KEY (required) REFERENCES Skill (sname) ); Answer the follow question by using hierarchical query. Find all skill names that required by a skill Database.

Task 18: PL/SQL programming The follow question refers to the relational tables created in page 14-15. 1. Define a stored procedure InspectionToday to display inspection appointment information that consist of buyer s phone number, property s location (include street number, street and city) and appointment time of today. The information should be displayed in the order of appointment time. Execute the procedure. 2. Define a stored function InspectionOfBuyer that takes a buyer s phone number and returns a string consists of the properties details that have been inspected (inspection date before today) by the buyer. A property attribute separated by a comma(,) with each other. Different properties inspected by the buyer separated by a new line (CHR(10)). Execute the function to find all buyers inspection information. Task 19: Concurrent transactions The follow questions refer to the relational tables created in page 14-15. Use a technique of presentation of concurrent execution of two database transactions explained to you during the lecture classes. Such that the statements of the first transaction are listed on the left-hand side of a page and the statements of the second transaction are listed on the right-hand side of a page. Make sure that each statement starts in a different line to represent a different moment in time when its execution starts. 1. Show a sample concurrent execution of two database transactions such that the execution reveals a deadlock. Thoroughly explain why the execution reveals a deadlock. Remember to set an appropriate isolation level for the transactions. Note, that a sample execution without the detailed explanations scores no marks. 2. Show a sample concurrent execution of two database transactions such that the execution ends up in a phantom phenomenon. Thoroughly explain why the execution ends up in phantom phenomenon. Remember to set an appropriate isolation level for the transactions. Note, that a sample execution without the detailed explanations scores no marks. 3. Show a sample concurrent execution of two database transactions such that the execution ends up in a non-repeatable read. Thoroughly explain why the execution ends up in non-repeatable read. Remember to set an appropriate isolation level for the transactions. Note, that a sample execution without the detailed explanations scores no marks.

4. Read the database transactions T 1 and T 2 included in SQL scripts below. T 1 : SELECT p#, price FROM Property; UPDATE Property SET price = price + 0.1*price WHERE city='sydney'; COMMIT; T 2 : UPDATE Property SET price = price + 5000 WHERE city IN ('Sydney', 'Wollongong'); INSERT INTO Inspection VALUES (12345678, 1000101, SYSDATE); SELECT p#, price FROM Property; COMMIT; Assume that a database user would like to concurrently run both transactions and assume that in the same moment no other transactions will be processed. What the best isolation levels would you execute each transaction at to avoid the corruption of the database and to achieve the best performance for each transaction? You have 3 options: READ ONLY, READ COMMITTED, and SERIALIZABLE. Note, that a sample execution without the detailed explanations scores no marks. End of sample problems