CMPT-354 D1 Fall 2008 Instructor: Martin Ester TA: Gustavo Frigo Final Exam With Solution
CMPT-354 D1 Fall 2008 Instructor: Martin Ester TA: Gustavo Frigo Final Exam With Solution
For every green Part, find the pid, the cheapest price and the number of its Suppliers.
This query cannot be formulated in relational algebra, since it has no group-by and no
aggregation operators.
SELECT P.pid, MIN(C.price), COUNT(C.sid)
FROM Part P, Catalog C
WHERE P.color = green AND P.pid = C.pid
GROUP BY P.pid;
b)
Find the pids of Parts that are supplied by every (!) Supplier in Vancouver and are supplied
by some (!) Supplier in Burnaby.
R1 ( pid , sidCatalog) /( sid ( city=VancouverSupplier)))
R 2 ( pid (Catalog( city=BurnabySupplier)))
R1 R2
Find the sid of Suppliers that supply exactly (!) one red Part.
name
sin
Employee
Traffic_Control_Staff
NOT OVERLAPS
Technicians
ISA
Traffic_Cont
rol_Staff
weight
modelNo
Technician
date_of_
exam
phone_
number
Traffic_Control_Staff
AND Technicians
COVER Employees
capacity
Model
Expert_
For
Type_of
date
regNo
faaNO
name
Test
score
Manages
Test_Info
Plane
a) Write down the complete SQL statements to create the relational schema, including PRIMARY
KEY, FOREIGN KEY and NOT NULL constraints. For the FOREIGN KEY constraints, you do
not need to specify the reactions to violating updates.
Your relational schema should satisfy the following two design criteria:
The number of tables should be minimal.
As many integrity constraints from the ER diagram as possible should be expressed.
CREATE TABLE Traffic_Control_Staff (sin VARCHAR(10),
name VARCHAR (20),
phone_number VARCHAR (20),
PRIMARY KEY (sin));
CREATE TABLE Technician (
sin VARCHAR(10),
name VARCHAR (20),
date_ of_exam DATETIME),
PRIMARY KEY (sin));
modelNo VARCHAR(10),
weight INTEGER,
capacity INTEGER,
PRIMARY KEY (modelNo))
regNo VARCHAR(10),
modelNo VARCHAR(10) NOT NULL,
PRIMARY KEY (regNo),
FOREIGN KEY (modelNo) REFERENCES Model)
sin VARCHAR(10),
modelNo VARCHAR(10),
PRIMARY KEY (sin, modelNo),
FOREIGN KEY (sin) REFERENCES Technician,
FOREIGN KEY (modelNo) REFERENCES Model)
faaNo VARCHAR(10),
name VARCHAR(20),
PRIMARY KEY (faaNo))
faaNo VARCHAR(10),
regNo VARCHAR(10),
sin VARCHAR(10),
date DATETIME,
score INTEGER,
PRIMARY KEY (faaNo, regNo, sin),
FOREIGN KEY (faaNo) REFERENCES Test,
FOREIGN KEY (regNo) REFERENCES Plane,
FOREIGN KEY (sin) REFERENCES Technician)
b) List the integrity constraints of the ER diagram that are not expressed in your relational schema.
The following integrity constraints are not expr essed in the above relational schema:
Participation constraint on Technician in relationship set Expert_For.
NOT OVERLAPS constraint on Technician and Traffic_Control_Staff.
a) Create a valid XML document (according to the above XML schema) with one book and one
article element. Assume that your XML document is stored in the same directory as the XML
schema bibliography.xsd.
<?xml version="1.0" encoding="ISO-8859-1"?>
<bibliography
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="bibliography.xsd">
<article key="100" >
<author>Author1 </author>
<author>Author2 </author>
<title>Title1 </title>
<year>Year1 </year>
</article>
<book key="200" >
<author>Author3 </author>
<title>Title2 </title>
<publisher>Publisher1 </publisher>
<year>Year2 </year>
</book>
</bibliography>
b) Consider an XML document bibliography.xml that conforms to the above XML schema.
Formulate the following query on this XML document in XQuery.
For all books and articles published after 2000, return a result element containing the key, the
title and the authors.
for $x in doc(bibliography.xml)/bibliography/*
where $x/year > 2000
return <result>
{$x/@key}
{$x/title}
{$x/author}
</result>
c) Consider again an XML document bibliography.xml that conforms to the above XML schema.
Formulate the following query on this XML document in XQuery.
For the oldest (those published in the earliest year) articles that have data mining in their title,
return the title and the authors.
let $as := doc(bibliography.xml)/bibliography/article
[contains(title,data mining)]
$m := min($a/year)
for $a in $as
where $a/year = $m
return
$a/title
$a/author