Docsity

Simple Midterm Exam for Database Systems | CSCI 585, Exams of Deductive Database Systems

Partial preview of the text

Download Simple Midterm Exam for Database Systems | CSCI 585 and more Exams Deductive Database Systems in PDF only on Docsity!

CSCI585- Database Systems

Sample Midterm

Please complete the following:

Name

Student ID#

Location (if remote or NTU)

DURATION: 1 Hour 15 Minutes

NOTE: Number of pages including this page: 24

Problem Max. Points Received Points

Please look over the entire exam first,

Select easy questions first, don’t panic,

Relax, and good luck!

Problem 1: (10 points)

Indicate whether each of the following statement is true or false (T/F):

___ 1.Entity Integrity Constraint: no two tuples can have the same combination of values for all their attributes.

___ 2. The degree of a relation is the number of fields and the cardinality of a relation instance is the number of tuples in it.

___ 3.Foreign-key cannot be NULL.

___ 4. All ternary relationship can be reduced to two or three binary relationships.

___ 5. Primary key is only unique across the relation, but Object Identity (OID) is a unique system-wide identifier_._

___ 6. R+-Tree has less insertion cost than R-Tree.

___ 7. In Total + overlap specialization, super-class cannot have primary key.

___ 8. PM1 quad-tree is data-independent

SQL related question:

___ 9. An expression in group-qualification must have a single value per group.

___ 10. A view is just a relation, but we store a definition, rather than a set of tuples.

___ 11. New tuple cannot be inserted in a view that has an aggregate inside.

THIS PAGE IS BLANK

(b) Reduce given ER diagram to relation using pure relational model. Be sure to identify all primary and foreign keys. (B and C are weak entities and they have b1 and c1 as their discriminators, respectively)

b1 b2^ c1 c

A R1 B R2 C

a

a

B C

r1 r

Problem 3: (10 points) (a) Consider the case,that a seller wants to put all expensive items on sale. Does the following SQL statement achieve the goal? If not, write the correct statement.

Update Items Set price=0.8*price Where price> (select avg(price) from Items)

THIS PAGE IS BLANK

THIS PAGE IS BLANK

Problem 4: (30 points) Consider the following ER diagram and its reduction.

Customers

Includes

CDs

Quantity

Orders Stores

Sells

Quantity

Price

Initiates

StoreID StoreName

Web Address

Address

Street

City

Zip

Address

Street

City

Zip

SSN

Name

Phone

Age

OrderID

Order Date

CDID

Title

Release Date

Artist

Genre

a) Write a SQL statement to find the name of stores that have less than 300 cds.

b) Complete the following SQL statement to find the name of the cds that has been ordered by no one younger than 18 in “Los Angeles” city:

SELECT CDs.title FROM CDs WHERE ……….. ( SELECT order_items.CDID FROM order_items, orders, customers WHERE order_items.orderID = orders.orderID AND orders.ssn = customers.ssn AND …………………………. AND …………………………. AND ………………………….);

c) Describe what the following SQL statement does?

SELECT s.storeName, SUM(si.price * oi.quantity) Total_Value FROM store_items si, order_items oi, stores s WHERE s.storeID = si.storeID AND oi.storeID = s.storeID AND oi.CDID = si.CDID GROUP BY s.storeName HAVING SUM(si.price * oi.quantity) >= ALL ( SELECT SUM(si1.price * oi1.quantity) FROM store_items si1, order_items oi1, stores s WHERE s1.storeID = si1.storeID AND oi1.storeID = s1.storeID AND oi1.CDID = si1.CDID GROUP BY s1.storeName );

THIS PAGE IS BLANK

Problem 5: (10 points)

Consider the following object-oriented concepts: a) Specialization b) Single Inheritance c) Multiple Inheritance d) Repeated Inheritance e) Overloading f) Abstraction

Now consider the following statements, which are provided to create a database using an object-relational model. For each sentence specify which of above concepts are applied:

1 …….. CREATE ROW TYPE A (a1 Integer, a2 Integer); 2 …….. CREATE ROW TYPE B (b1 Integer); 3 …….. CREATE ROW TYPE C (c1 A, c2 Integer) UNDER B; 4 …….. CREATE ROW TYPE D (d1 A, d2 Integer) UNDER B; 5 …….. CREATE ROW TYPE E (e1 A, e2 Integer) UNDER D; 6 …….. CREATE FUNCTION F (f1 B) RETURNS Integer; 7 …….. CREATE FUNCTION F (f1 C) RETURNS Integer; 8 …….. CREATE FUNCTION F (f1 A) RETURNS Integer; CREATE TABLE TD USING D; CREATE TABLE TE USING E; 9 …….. SELECT TD.d2, TE.e FROM TD, TE WHERE TD.d1 = TE.e1; 10 …….. SELECT e1, e FROM TE ORDER BY e1;

Problem 6: (10 points)

Assume the following table for the position of some of the buildings in Los Angeles is stored in a database with spatial support.

ID Name Shape Spatial Data 1 Staples Center Circle origin: (13,20) radius: 2 Pershing Square Square center: (37.5, 50) length: 8 3 Bonaventure Hotel Octagon (13,70) (15.2,68.2) (19.68.2) (21,70) (21,72.8) (19,74.8) (15.2,74.8) (13,72.8) 4 Library Tower Circle origin: (55,70) radius: 5 Arco Towers Square center: (15.5, 52.5) length: 5

Assume that the rows are inserted in to the table as they appear above. Also, assume that (m,M)=(2,4).

a) Draw resulting R-Tree index for the above table. Please note that you need to draw the corresponding index after each insertion. In other words, you should draw five R-Trees here. (For the first four trees, you could get 1 point for each correct one. For the 5 th^ tree, you could earn 6-point reward if the answer is correct. Please use “Quadratic” method to split the node.)

b) In order to search some object in R-Tree, you might have to go through several rectangles or the whole database. Why? How could R+-Tree solve this problem? (3 points)

c) Please describe one common drawback for R-Tree and R+-Tree. (2 points)