Um6p Cs Introdb 2023 Midterm Exam Solutions
Um6p Cs Introdb 2023 Midterm Exam Solutions
Question 1 (3 points)
Solution:
• Entities = 0.75 pt (0.25 each)
• Attributes = 0.5 pt
• Primary keys = 0.75 pt (0.25 each)
• Relationship and cardinality = 1 pt (0.50 each with its cardinalities)
Received
RetailCenter
Question 2 (2 points)
Solution:
Question 1 (2 points)
Solution: (1 pt each)
a. ρ(E1,Enrollment)
ρ(E2,Enrollment)
ρ(E3 (1->stid, 2->cid 3->grade),E1 ⨝E1.grade < E2.grade E2))
πstid (E1 – πstid,cid,grade E3)
b. ρ(B, πcid (Courses) )
ρ(A, πstid,cid(Enrollment) )
ρ(Temp1, πstid(A) x B)
ρ(Temp2, Temp1 - A)
πstid ( A) – πstid (Temp2)
c. ρ(C1,Course_Offerings)
ρ(C2, Course_Offerings)
ρ(C3 (1->sid, 2->cid 3->fee),C1 ⨝C1.fee < C2.fee C2))
πcid (C1 – πsid,cid,fee C3)
Question 1 (3 points)
Solution:
a. (0.5 pt)
B+ = B (B→B)
= BC (B→C)
= BCD (C→D)
= ABCD (C→A)
so the candidate key is B.
B is the ONLY candidate key, because nothing determines B
b. (1 pt)
R is not 3NF, because:
C→D causes a violation,
C→D is non-trivial ({D} ⊄ {C}).
C is not a superkey.
D is not part of any candidate key.
C→A causes a violation
Similar to above
B→C causes no violation
Since R is not 3NF, it is not BCNF either
Question 2 (2 points)
Solution:
1. (0.5 pt) Notice that we have single attribute on the RHS in all FDs, we need to look
for extraneous (redundant) attributes on the LHS and also look for FDs that are
redundant. We will apply the steps summarized in the document week3-notes.pdf
(section 3.3.4).
2. (1 pt) Find extraneous attributes on the LHS.
Consider ACD -> B to see if any of the three attributes on the LHS is extraneous. Start with
A. We need to compute ({ACD} – A)+ using the dependencies in F and check if the result
contains A; if it does, attribute A is extraneous.
Computing CD+, we get ACDEGB which contains A and therefore, A is extraneous. Also
the closure contains B, which tells us that CD -> B holds.
So the current set of FDs after step2 is :: {AB -> C, C -> A, BC -> D, D -> E, D -> G, BE ->
C, CG -> B, CG->D, CE -> A, CE -> G , CD->B}
Minimal Cover: {AB -> C, C -> A, BC -> D, D -> E, D -> G, BE -> C, CG -> D, CE -> G,
CD -> B}
Note that the minimal cover is not unique, depending on the order in which the FDs are
processed. For example, if we process the FD: CD->B first in step3, then the resulting
minimal cover is: {AB -> C, C -> A, BC -> D, D -> E, D -> G, BE -> C, CG -> B, CE -> G}
Question 1 (2 points)
a.
r1 r2 s1 s2
3 3 3 2
4 6 4 1
b.
r1 r2 s1 s2
1 7 Nul null
l
2 5 Nul Nul
l l
3 3 3 2
4 6 4 1
c.
r1 r2 s1 s2
3 3 3 2
4 6 4 1
null null 5 0
null null 6 3
d.
r1 r2 s1 s2
1 7 Nul null
l
2 5 Nul null
l
3 3 3 2
Question 2 (2 points)
a. List the names of the products that cost over 100 dhs and the names of the companies that
sell them
b. List the company id of all the companies that only sell products that cost over 200 dhs.
c. List the company id of all the companies that do not sell any products.
d. For each company, list the company id and the name of its most expensive product. If
multiple products are tied for highest price, return all of them.
Question 3 (1 point)
ON DELETE NO ACTION means that a parent cannot be deleted if it has children. Although
this is the default in most DBMS systems, it is better to explicitly state it to indicate to other
programmers the intended outcome so nobody mistakenly adds ON DELETE CASCADE.
b. The main idea here is to use the VIEW statement which enables logical data
independence by insulating changes in the database schema from application code.
Alternatively, the Product_New table could contain only pname and Offers contain price and
the View Product would be a simple select from the offers table.