0% found this document useful (0 votes)
26 views4 pages

Homework 1 Solution

Uploaded by

Krystal Yeung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

Homework 1 Solution

Uploaded by

Krystal Yeung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Homework 1

(Due: Friday 19-Feb-2021 at 23:59 pm)

You must upload your solution as a PDF or MS Word file on Canvas.

Question A. (50 marks)

1) Design a database that can be used to keep track of various aspects of a TV


show streaming service:

• Each TV show has a unique name, a rating (1-10), and a set of producers.
• A TV show may have multiple (i.e. zero or more) seasons, and for each
season we keep track of the season number and the release date.
• A season consists of multiple (i.e. zero or more) episodes. For each
episode, we store its number within the season, and the length.
• An actor has a unique name and we keep track of the date of birth. Each
actor may play a character in an episode, and, in that case, we store the
name of the character played by the actor.
• For each user of the streaming service, we store a unique user ID and a
credit card number.
• A user can add TV shows to the user’s wish list.
• We associate each TV show with one genre, which has a unique name
(e.g., drama, thriller, etc) and a description.
• The service provides the option for each user to subscribe to any number
of genres.
Design an ER diagram that models the above aspects of the streaming service.
Make sure to identify weak entities and annotate the cardinality of the relationships
between entities. You must state any additional assumptions that you make. [30
marks]

2. Convert your ER diagram into a relational schema using the mapping


guidelines discussed in the lecture. For each relation (i.e. table) obtained,
specify the name and its attributes, as well as the primary key and foreign
keys (if any). [20 marks]

Question B. [50 marks]

Consider the relation R={A,B,C,D,E,F,G,H,I,J}and the set of functional


dependencies F={{A,B}→{C},{A}→{D,E},{B}→{F},{F}→{H},{D}→{G,I,J}}.
a. Prove that {A}→{E,G} holds by using the FD inference rules. (10 marks)
b. Determine whether {A,B,C} is a super key or a candidate key. Justify your
answer. (10 marks)
c. Determine whether {A,F} is a super key or a candidate key. Justify your
answer. (10 marks)
d. Decompose R into 2NF. (10 marks)
e. Decompose R into BCNF. (10 marks)
Solutions

Question A1)

Note: This is just *one* possible solution.

Nome Rating Producer


SIuynter Date
i

wish list n 1 n
TVs how Season
n Nome Rating Producer
SIuynter Date
y
i

m wish list n 1 n
TVs how Season
y n
n character p
n Genre n Episode
User m
m plays.in
subscribe
n
I GName y
Description character
UID CCNumber ENenekee
n Length
User m n Genre M Episode
plays.in
subscribe
I GName Description
UID CCNumber Actor M
Ekunekee Length

Name DOB
Actor

Name DOB
Alternative (for lower-right part of ER diagram):

Alternative Solution

character
e
Name
n Episode
plays.in

ENenekee Length
m

Actor

Name DOB

Question A2)

TVShow( Name, Rating, GName )


Foreign keys: GName
Genre( GName, Description )

User( UID, CCNumber )

Actor( Name, DOB )

Season( SNumber, Date, ShowName )


Foreign keys: ShowName refers to TVShow(Name)

Episode( ENumber, Length, SNumber, ShowName )


Foreign keys: ShowName refers to TVShow(Name), SNumber

Subscribe( UID, GName )


Foreign keys: UID, GName

Plays_In( ActorName, ENumber, SNumber, ShowName, Character )


Foreign keys: ActorName, ENumber, SNumber, ShowName

Wish_List( UID, ShowName )


Foreign keys: UID, ShowName

Producer( ShowName, ProducerName )


Foreign keys: ShowName

Question B)

a. One possible approach (there are many ways):

1) Given {A}→{D,E}
2) Applying decomposition rule to 1): {A} à {E}
3) Given {D}→{I,J,G}
4) Applying decomposition rule to 3): {D}→{G}
5) Applying decomposition rule to 1): {A}→{D}
6) Applying transitive rule to 5) and 4): {A}→{G}
7) Applying union rule to 2) and 6): {A}→{E,G}

b. Compute the closure {A,B,C}+={A,B,C,D,E,F,G,H,I,J}. This closure contains all


attributes of R and therefore {A,B,C} is a superkey. To check whether it is a
candidate key, we need to show that it is a minimal
superkey: {A,B}+={A,B,C,D,E,F,G,H,I,J}, which also contains all attributes.
Therefore {A,B,C} was not a minimal key and hence it is not a candidate key.
c. We proceed analogously to (b): {A,F}+={D,E,G,I,J}. This doesn’t contain all
attributes and hence it is neither a superkey nor a candidate key.

d. We only have one candidate key of R, namely {A,B}. The nonprime


attributes {D,E,F,G,H,I,J} have a partial dependency on the key {A,B}. We
decompose R as follows:
o R1(A,B,C)
o R2(A,D,E,G,I,J)
o R4(B,F,H)

e. We need to break up the transitive dependencies in R2 and R4. We keep


relations R1 and R3 as is. We decompose R2 into:

• R2,1(A,D,E)
• R2,2(D,G,I,J)
We decompose R4 into:

• R4,1(B,F)
• R4,2(F,H)

You might also like