This is a relatively long written assignment covering quite a bit of material. Please plan accordingly.
(a) Specify your database design using ODL. In addition to class (interface) definitions with attributes and relationships, don't forget to include keys and inverse relationships as appropriate. Note that there are many choices to make in designing an ODL schema for this database - there is no single right answer to this question by any means, although some answers may be better than others.
(b) Using the method for translating an ODL design into relations, produce a set of relations for your database design. In the cases where different mappings to relations are possible, choose whichever one you think is more appropriate. Be sure to specify (underline) keys for all relations.
(a) Give an example of an ODL class (interface) definition and a key for the class such that the key includes at least one relationship, and there is no natural key for the class that includes only attributes. Use any real-world domain you find appropriate.
(b) What concept in the entity-relationship model corresponds to an ODL class where a relationship is needed in the key?
interface Athlete (key (name,jerseyNumber)) { attribute string name; attribute int jerseyNumber; attribute int year; } interface BasketballPlayer: Athlete { attribute string position; attribute Set <Struct{string bodypart,int severity}> Injuries; relationship Set<Commercial> starredIn inverse Commercial::star; } interface Commercial { attribute string company; attribute string product; relationship BasketballPlayer star inverse BasketballPlayer::starredIn; }Convert this design into an object-relational design based on the SQL3 standard as covered in class and the textbook. Show the definitions of any row types or value types you use, along with the actual relations. Be sure to specify (underline) keys for all relations. If any of your relations are not in Boyce-Codd Normal Form (BCNF) or not in Fourth Normal Form (4NF), please say so and explain why.
create row type AddressType as (street string, city string) create row type StudentType as (name string, address AddressType) create row type CollegeType as (name string, city string) create table Student of type StudentType create table College of type CollegeType create table Attends(student ref(StudentType), college ref(CollegeType), tuition integer) create table Roommates(student1 ref(StudentType), student2 ref(StudentType))Write SQL3 queries for each of the following. You may assume that student and college names are unique, that all students have exactly one address, attend one college, and have one roommate, and that all colleges are located in exactly one city.
(a) Find the names of all students who live in Palo Alto.
(b) Find the names of all students who attend Stanford.
(c) Find the names of all students who live in the same city as the college they attend and pay tuition of at least $10,000.
(d) Find the names of all students who live in the same city and on the same street as their roommate. (Let's assume that addresses in the database are home addresses and not college addresses - otherwise this query would return everyone.)
Sales(saleID,date,itemID,color,size,qty,unitPrice)
Consider the following two queries over the Sales relation:
// Total revenue grouped by date and item: SELECT date, itemID, SUM(Qty*unitPrice) FROM Sales GROUP BY date, itemID // Total revenue grouped by item and color SELECT itemID, color, SUM(qty*unitPrice) FROM Sales GROUP BY itemID, color
Specify a view V over the Sales relation. You should choose V so that if V is stored as a materialized view, then V can be used to substantially speed up the execution of both of the above queries, assuming that the Sales relation is very large. In addition to specifying V, show how each of the two queries above can be rewritten into an equivalent query that uses V instead of Sales.
We want to mine from this relation all single-attribute association rules with certain support and confidence thresholds (as defined in class). Specifically, write a SQL query that produces all pairs of itemID's [I1,I2] such that I1->I2 is an association rule with support > 0.1 and confidence > 0.6. If you find it useful to define a sequence of one or more views used by the final query you may do so.
(b) Now your friend wants to pose a query over your data, specifically she wants to find the instructors of all courses in which you are expecting to receive an "A" grade. Based on the XML structure in part (a), write this query using any (or all) of the XML query languages discussed in class. (If you prefer to use an XML query language not discussed in class, you are welcome to do so as long as you name and provide a citation for the language.)