Assignment 1

Due date: Wednesday, October 1st, 5:30PM, in class.
NOTES:
This assignment is meant to give you practice with the fundations of database systems, the relational model (keys and constraints), SQL and Relational Algebra.

Question 1 (2 points)

Exercise 1.2, Page 23. Explain it in in your own words.

Question 2 (3 points)

Exercise 1.4, Page 23. Explain it in in your own words.

Question 3 (5 points)

Assume that attributes with the same name in different relations represent the same domain and that the primary key attributes in each relation are underlined. Answer the following questions given the relational schema below:
Rel1(A, B, C, D)
Rel2(B, C, D, E, F, G)
Rel3(D, H, I)
Rel4(J, D, K, H)
  1. List all potential foreign keys in the four relations. (1 point)
  2. List all superkeys of Rel2. (1 point)
  3. List all candidate keys of Rel3. (1 point)
  4. What is the degree and cardinality of Rel4? (1 point)
  5. If the cardinality of Rel4 is m, what is the cardinality of π D,H(Rel4)? (1 point)

Question 4 (10 points)

Alice and Brian are two students who took the CS 448 some years ago. Now, years later, they meet and challenge themselves about their understanding of the relational model. Alice proposes the following relation schemas.
Rel1(A: string, B : integer, C : string)
Rel2(B : integer, D : string, E : integer, F : string)
Rel1.B is a foreign key to Rel2.B.
F is a UNIQUE KEY for Rel2. Alice asks Brian to provide an instance for the above relation. Here is the instance given by Brian:
Rel1(A, B, C)
A BC
null 1 up
aa null 100
bb 3 up
cc 4 null
dd 4 down
Rel2(B, D, E)
B D E F
1 Ted1one
2 Fredditwo
4 Joenullnull
5 null1four
6 Jedabfive
List ALL constraint violations of Brian's instance with respect to the schema givem by Alice.

Question 5 (80 points)

Assume the following relational schemas
ProductionHouse(pid, name, location, president)
Produce(pid, mid, manHour)
Movies(mid, title, director)
Below are a number of database queries formulated in English. Express these queries using SQL and Relational Algebra. If a query cannot be expressed in one of these languages, provide an explanation.
  1. Find the names of Production Houses that produce some movies directed by Ben Affleck.
  2. Find the pid of Production Houses that produce some movies directed by Ben Affleck or Peter Jackson.
  3. Find the pid of Production Houses that produce some movies directed by Ben Affleck and some movies directed by Peter Jackson.
  4. Find the pid of Production Houses that produce some movies directed by Ben Affleck or are located in "Ney York".
  5. Find the pid of Production Houses that produce all movies directed by Ben Affleck.
  6. Find the pid of Production Houses that produce only movies directed by Ben Affleck or by Peter Jackson.
  7. Find the pid of Production Houses that produce at least two movies directed by Ben Affleck.
  8. Find the pid of Production Houses that produce the largest number of movies.
  9. Show pid, name and the total manHours for each Production House.
  10. Show pid, name and the total manHours for each Production House that has produced at least 5 movies.