Individual Assignment 2
Individual Assignment 2
INDIVIDUAL ASSIGNMENT 2
Due: 16/07/20
Question 1
(ii ) foreign key and how it can specify a referential integrity constraint
between two relations; [4 marks]
Question 2
(a) What is the difference between a key and a functional dependency? [3 marks]
A, B → C
B, C → D
C, D → E
D, E → A
1
Question 3
(iii ) Decompose the schema to BCNF in two different ways. In each case, are
all dependencies preserved? Explain. [4 + 4 marks]
Question 4
(b) The core relational algebra is often extended with other operators. For the
following operators give a definition and an example of their behaviour:
(c) X, Y and Z are all relations with a single attribute A. A naı̈ve user wishes
to compute the set-theoretic expression X ∩ (Y ∪ Z) and writes the following
SQL query.
SELECT X.A
FROM X,Y,Z
WHERE X.A=Y.A OR X.A=Z.A
(i ) Give the relational algebra term that this query would be compiled to.
[2 marks]
(ii ) Does the SQL query satisfy the user’s expectation? Justify your answer.
[4 marks]
2
Question 5
Assume a simple movie database with the following schema. (You may assume
that producers have a unique certification number, Cert, that is also recorded in
the Movie relation as attribute prodC#; and no two movies are produced with the
same title.)
Movie(title,year,length,prodC#)
StarsIn(movieTitle,movieYear,starName)
Producer(name,address,cert)
MovieStar(name,gender,birthdate)
(i ) Who were the male stars in the film The Red Squirrel ? [1 mark]
(b) SQL has a boolean-valued operator IN such that the expression s IN R is true
when s is contained in the relation R (assume for simplicity that R is a single
attribute relation and hence s is a simple atomic value).
Consider the following nested SQL query that uses the IN operator:
SELECT name
FROM Producer
WHERE cert IN (SELECT prodC#
FROM Movie
WHERE title IN (SELECT movieTitle
FROM StarsIn
WHERE starName='Nancho Novo'));
(iii ) Is your query from part (b)(ii ) always equivalent to the original query? If
yes, then justify your answer; if not, then explain the difference and show
how they could be made equivalent. [6 marks]
(c) SQL has a boolean-valued operator EXISTS such that EXISTS R is true if and
only if R is not empty.
Show how EXISTS is, in fact, redundant by giving a simple SQL expression
that is equivalent to EXISTS R but does not involve EXISTS or any cardinality
operators, e.g. COUNT. [Hint: You may use the IN operator.] [8 marks]
3
Question 6
(iii ) If you were designing a relational database system, how would your
approach to schema design differ for OLTP and OLAP systems?
[3 marks]
(iv ) In OLAP, what is the meaning of the terms drill down, roll up, and slice?
[3 marks]
where the underlined attributes represent the primary keys of the associated
relation. The table SuppliedBy implements a relationship between suppliers
and parts — indicating which parts are supplied by which supplier — using
foreign keys pointing into the Parts and Supplier tables. The weight attribute
is the parts weight in grams.
Write an SQL query that will return a list, without duplicates, of all postcodes
associated with suppliers of parts less than one kilogram in weight. [5 marks]
(c) Define and explain the ACID properties of database transactions. [4 marks]