Download homework 5: Answers

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Database wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Clusterpoint wikipedia , lookup

PL/SQL wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
CSE 880, Fall 2014
Advanced Database Systems
Homework 5:
Object-Oriented Databases- ANSWERS
Due: October 22, 2014
1. (10 points) Write a schema using graphical representation (similar to
the student-course-TA example for ODMG handout in class) for the
following object classes:
project, document, project-leader, research-paper and dbresearch-paper.
Use document-IF as an interface class for document, document is a
subclass of document-IF and research-paper is a subclass of document.
db-research-paper is a subclass of research paper. Use the following
relations between the classes:
project has a set of documents and a project leader. Project leaders
publish research-papers. Make appropriate assumptions on the cardinalities of the relations.
document_IF
project_documents
has_documents
document
project
is-led-by
research_paper
authors
leads
project_leader
has_research_papers
dbresearch_paper
2. (10 points) Most object-oriented data models restrict an object to being
an instance of a single class. However, an object can be a member of
several classes by means of inheritance hierarchy (substitutability). For
example, Student class and Pilot class are subclasses of Person class
and a person P is both a student and a pilot. To allow this by a data
model, to be an instance of both Student class and the Pilot class,
ambiguities between the classes need to be handled. Describe a few
such ambiguities. If the data model restricts an object to being an
1
instance of a single class, suggest how multiple inheritance by creating
Student-Pilot class can handle the situation.
ANSWER:
Name- collisions for attributes and methods have to be resolved. If any
changes are made to any one of the classes that have to be resolved as
well.
If the data model allows only one instance per class then Student-Pilot
class will inherit from Student and Pilot class and all conflicts can be
resolved by the inheritance rules.
3. (10 points) Write OQL statements for the following queries using the
schema for Project-Task database given in the class:
(a) Get all those Documents that the participating members of those
tasks with description ”Database design” have published, i.e., if
there a member of a task who have published on ”database Design”, corresponding task and it’s documents are to be selected.
In the following D* implies all documents, including technical reports and articles.
SELECT D.acronym_document,D.name,D.classification
FROM Project P , P.document D*, P.work_plan T
WHERE "Database Design" IS IN (SELECT description_task
FROM T)
(b) Get all project names for those projects with a task leader who is
author of some article.
SELECT P.project_name
FROM Project P, P.work_plan T
WHERE exists (SELECT *
FROM T
WHERE T.leader.name IS IN
(SELECT * FROM Article.author Au
WHERE EXISTS (SELECT *
FROM Au
WHERE Au == T.leader.name)
NOTE: == for Object ID equality
4. (a) Create the following three types in Oracle object-relational database.
These types correspond to the entity sets given in the EER diagram of the sports database of homework 1.
Employee-type(Eno, Ename, Eaddress)
Player-type(PlayingPosition)
Playing-coach-type(YrsExperience)
2
Assume that Employee-type is NOT INSTANTIABLE (note that
a method can also be defined as NOT INSTANTIABLE where
only interface of the method is defined with the type definition and
the implementations of the method are created in the subtypes).
Further assume that Playing-coach-type is a subtype of ONLY
Player-type (Oracle does not support multiple inheritance). Do
not forget to include NOT FINAL in Employee-type and Playertype.
(b) Create a table Players of Player-type. Insert into this table two
tuples, one of type Player-type and the other of type Playingcoach-type.
(c) Redefine the type to prevent inserting tuples of Playing-coach-type
into the table Players.
(d) Indicate if tuples of Player-type can be inserted into a table of
Playing-coach-type.
5. Answer the following question for Oracle Object-Relational database.
(a) (5 points) Define an object-relational schema, using nested tables,
for the following entity set:
Students(sid, addresses, TelNo)
sid is the student ID, addresses and TelNos are multi-valued.
create type address(
name varchar2(20),
zip varchar2(5)
)
create type telnotype(
telno varchar(9))
create type telNostype AS table of telnotype;
create type addresses AS table of address type;
create table students (
sid varchar2(30),
addresses addresses,
TelNo telNostype)
NESTED TABLE addresses STORE AS addressTable,
NESTED TABLE telNo STORE AS TelNoTable;
(b) Consider the following SQL statement:
Select *
From THE(Select addresses
From Students S
Where S.sid=1234) A
Where A.city= "East Lansing"
3
i. (5 points) What does the keyword THE accomplishes?
It allows accessing multiple addresses in the tiny tables.
ii. (5 points) Give the meaning of the above SQL statement in
plain English.
It selects all the attributes from the Students table where city
is East Lansing and sid is 1234.
(c) (5 points) Give an SQL statement for inserting telephone number
517-333-3333 into the nested table (tiny table) for the student
with sid=1234.
INSERT INTO THE(Select TelNo from Students S where S.sid=1234)
VALUES(telNo(’517-333-3333’));
4