

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Question 1. Suppose you are given the following relations. Write down tables that correspond to these relations in SQL with CREATE TABLE statements by listing each attribute with an appropriate data type, listing all keys by primary key constraints and giving the appropriate rationale (you can assume names are unique for this homework to simplify the question). The length of character strings is not important, use varchar(255) for all.
CREATE TABLE person ( name varchar(255), dateOfBirth date, PRIMARY KEY (name) )
Each person has a unique name but multiple people may be born on the same day.
CREATE TABLE club ( name varchar(255), dateFounded date, PRIMARY KEY (name) )
Each club has a unique name but clubs may be founded on the same day.
CREATE TABLE clubMember ( personName varchar(255), clubName varchar(255), PRIMARY KEY (personName, clubName) )
Each person has a unique name and each club has a unique name. Each person can only be a member of each club once.
CREATE TABLE clubActivity ( clubName varchar(255), title varchar(255), date date, time time, PRIMARY KEY(clubName, title, date) )
An activity should only occur once a day for each club but the time that an activity occurs can change from one day to the next (as meeting times commonly do). If, however, a club wishes to meet for a different activity on the same day (say board games wants to play Battlestar Galactica at 4pm then Arkham Horror at 6pm both on 8-01-2010, the same day as Carcassone) then this should be (and is) allowed.
Question 2. Assuming the above data model and instance, for each query below, write down (1) what is a good English sentence that describes what the query is returning, (2) what is the result of the query (i.e. which attributes and tuples are in the result)?
a. (Πname Club)−(Πname(Club ./name=ClubN ame and date>dateF ounded ClubActivity))
The name of any club that has not had an activity since its founding.
Result: name skiing
b. P erson ./name<>n 1 and dateOf Birth=d 1 (ρP 1(n 1 ,d 1 ,p 1 ,a1)(P erson))