Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Introduction to databases Assignement 2

Question 1:
Π σ σ
1. (𝑝𝑟𝑖𝑐𝑒 < 20((𝑑𝑛𝑎𝑚𝑒 = "𝐷𝑜𝑙𝑖𝑝𝑟𝑎𝑛𝑒" 𝐷) ⋈ 𝐼) ⋈ 𝑃)
𝑝𝑐𝑖𝑡𝑦
Π σ σ σ σ
2. 𝑝𝑛𝑎𝑚𝑒 𝑝𝑐𝑖𝑡𝑦 = "𝑀𝑎𝑟𝑎𝑘𝑘𝑒𝑐ℎ"(𝑝𝑟𝑖𝑐𝑒 < 20(𝑑𝑛𝑎𝑚𝑒 = "𝐷𝑜𝑙𝑖𝑝𝑟𝑎𝑛𝑒"((𝑚𝑐𝑜𝑢𝑛𝑡𝑟𝑦 = "𝑀𝑜𝑟𝑜𝑐𝑐𝑜" 𝑀) ⋈ 𝐷) ⋈ 𝐼) ⋈ 𝑃)

3. Let:
Π σ σ
𝑝𝑐𝑖𝑡𝑦 𝑝𝑟𝑖𝑐𝑒 < 20 𝑑𝑛𝑎𝑚𝑒 = "𝐷𝑜𝑙𝑖𝑝𝑟𝑎𝑛𝑒" 𝐷) ⋈ 𝐼) ⋈ 𝑃)
𝐷= ( ((

Π σ σ
𝐴= (𝑝𝑟𝑖𝑐𝑒 < 20((𝑑𝑛𝑎𝑚𝑒 = "𝐴𝑠𝑝𝑒𝑔𝑖𝑐" 𝐷) ⋈ 𝐼) ⋈ 𝑃)
𝑝𝑐𝑖𝑡𝑦
𝑟𝑒𝑠𝑢𝑙𝑡 = 𝐷 ∩ 𝐴

4. Let:
Π σ σ
𝐷= (𝑝𝑟𝑖𝑐𝑒 < 20 ((𝑑𝑛𝑎𝑚𝑒 = "𝐷𝑜𝑙𝑖𝑝𝑟𝑎𝑛𝑒" 𝐷) ⋈ 𝐼) ⋈ 𝑃)
𝑝𝑛𝑎𝑚𝑒
Π σ σ
𝐴= ( (( 𝐷) ⋈ 𝐼) ⋈ 𝑃)
𝑝𝑛𝑎𝑚𝑒 𝑝𝑟𝑖𝑐𝑒 < 20 𝑑𝑛𝑎𝑚𝑒 = "𝐴𝑠𝑝𝑒𝑔𝑖𝑐"

𝑟𝑒𝑠𝑢𝑙𝑡 = 𝐷 ∪ 𝐴

5. Let:
Π σ σ σ
𝐷= ((𝑝𝑟𝑖𝑐𝑒 < 20(𝑑𝑛𝑎𝑚𝑒 = "𝐷𝑜𝑙𝑖𝑝𝑟𝑎𝑛𝑒" (𝑚𝑐𝑜𝑢𝑛𝑡𝑟𝑦 = "𝑀𝑜𝑟𝑜𝑐𝑐𝑜" 𝑀) ⋈ 𝐷) ⋈ 𝐼) ⋈ 𝑃)
𝑝𝑛𝑎𝑚𝑒
Π σ σ σ
𝐴= (( ( ( 𝑀) ⋈ 𝐷) ⋈ 𝐼) ⋈ 𝑃)
𝑝𝑛𝑎𝑚𝑒 𝑝𝑟𝑖𝑐𝑒 < 20 𝑑𝑛𝑎𝑚𝑒 = "𝐴𝑠𝑝𝑒𝑔𝑖𝑐" 𝑚𝑐𝑜𝑢𝑛𝑡𝑟𝑦 = "𝑀𝑜𝑟𝑜𝑐𝑐𝑜"
𝑟𝑒𝑠𝑢𝑙𝑡 = 𝐷 ∪ 𝐴

6. Let:
Π σ
𝑝𝑖𝑑, 𝑑𝑖𝑑 𝑚𝑐𝑜𝑢𝑛𝑡𝑟𝑦 = "𝑀𝑜𝑟𝑜𝑐𝑐𝑜" 𝑀) ⋈ 𝐷 ⋈ 𝑃)
𝐴= ((

Π
𝐵= 𝐼
𝑝𝑖𝑑, 𝑑𝑖𝑑
Π
𝑝𝑛𝑎𝑚𝑒((𝐴 − 𝐵) ⋈ 𝑃)
𝐶=

Π
𝑟𝑒𝑠𝑢𝑙𝑡 =
𝑝𝑛𝑎𝑚𝑒𝑃 − 𝐶
7.
𝑟𝑒𝑠𝑢𝑙𝑡 = 𝐵 ∕ 𝐴
Π Π Π
8. 𝐵− (( 𝐵 × 𝐴) − 𝐵)
𝑝𝑖𝑑 𝑝𝑖𝑑 𝑝𝑖𝑑
Introduction to databases Assignement 2

9. Let:
Π (( σ
𝐴=
𝑑𝑖𝑑 𝑚𝑐𝑜𝑢𝑛𝑡𝑟𝑦 = "Morocco" ∨ "𝐶𝑎𝑛𝑎𝑑𝑎" 𝑀) ⋈ 𝐷)
Π
𝑝𝑖𝑑, 𝑑𝑖𝑑 𝐼
𝐵=

𝑟𝑒𝑠𝑢𝑙𝑡 = 𝐵⁄𝐴

10. Let’s note question 7’s result for Morocco M and for Canada C:
𝑟𝑒𝑠𝑢𝑙𝑡 = 𝑀 ∪ 𝐶

11. Let: 𝐼1 = 𝐼2 = 𝐼
Π σ
( 𝐼 × 𝐼2 )
𝑝𝑖𝑑1, 𝑝𝑖𝑑2 𝑑𝑖𝑑1 = 𝑑𝑖𝑑2 ∧ 𝑝𝑟𝑖𝑐𝑒1 > 𝑝𝑟𝑖𝑐𝑒2 ∧ 𝑝𝑖𝑑1 ≠ 𝑝𝑖𝑑2 1
12. Let: 𝐼1 = 𝐼2 = 𝐼

Π Π σ
𝐴= (𝐼 − ( ( (𝐼 × 𝐼2 )) (1 → 𝑝𝑖𝑑, 2 → 𝑑𝑖𝑑, 3 → 𝑝𝑟𝑖𝑐𝑒)))
𝑝𝑖𝑑 𝑝𝑖𝑑, 𝑑𝑖𝑑, 𝑝𝑟𝑖𝑐𝑒 𝑝𝑟𝑖𝑐𝑒1 < 𝑝𝑟𝑖𝑐𝑒2 1

Π
𝑟𝑒𝑠𝑢𝑙𝑡 = (𝐴 ⋈ 𝑃)
𝑝𝑛𝑎𝑚𝑒
Π
13. Let: 𝐼1 = 𝐼2 = 𝐼 − (𝐴 ⋈ 𝑃)
𝑝𝑖𝑑, 𝑑𝑖𝑑, 𝑝𝑟𝑖𝑐𝑒 𝑞𝑢𝑒𝑠𝑡𝑖𝑜𝑛 12

Π Π σ
𝐴= (𝐼 − ( ( (𝐼 × 𝐼2 )) (1 → 𝑝𝑖𝑑, 2 → 𝑑𝑖𝑑, 3 → 𝑝𝑟𝑖𝑐𝑒)))
𝑝𝑖𝑑 𝑝𝑖𝑑, 𝑑𝑖𝑑, 𝑝𝑟𝑖𝑐𝑒 𝑝𝑟𝑖𝑐𝑒1 < 𝑝𝑟𝑖𝑐𝑒2 1

Π
𝑟𝑒𝑠𝑢𝑙𝑡 = (𝐴 ⋈ 𝑃)
𝑝𝑛𝑎𝑚𝑒

14. Let: 𝐼1 = 𝐼2 = 𝐼

Π Π σ
𝐴= (𝐼 − ( (𝑝𝑟𝑖𝑐𝑒1 > 𝑝𝑟𝑖𝑐𝑒2(𝐼1 × 𝐼2 )) (1 → 𝑝𝑖𝑑, 2 → 𝑑𝑖𝑑, 3 → 𝑝𝑟𝑖𝑐𝑒)))
𝑝𝑖𝑑 𝑝𝑖𝑑, 𝑑𝑖𝑑, 𝑝𝑟𝑖𝑐𝑒

Π
𝑟𝑒𝑠𝑢𝑙𝑡 = (𝐴 ⋈ 𝑃)
𝑝𝑛𝑎𝑚𝑒

Question2:
1. no.
Let’s take for example: 𝑅 = {1,2,3,4,5,6}, 𝑇 = {1,2,3} 𝑎𝑛𝑑 𝑆 = {4,5}
Well, we have:
𝑅 − 𝑇 = {4,5,6}
𝑅 − 𝑆 = {1,2,3,6}
Introduction to databases Assignement 2

So,
(𝑅 − 𝑆) ∪ (𝑅 − 𝑇) = {1,2,3,4,5,6}
Therefore,
𝑇 ∪ 𝑆 = {1,2,3,4,5}
So,
𝑅 − (𝑇 ∪ 𝑆) = {6}
Which proves that: (𝑅 − 𝑆) ∪ (𝑅 − 𝑇) ≠ 𝑅 − (𝑇 ∪ 𝑆)
2.

• If we consider the case in which there are more attributes in C than the ones in Z
then the expressions are equivalent since we cannot switch the projection and select
operators. (Π𝑧 𝜎𝑐 ≠ 𝜎𝑐 Π𝑧 ).
• But if we assume that the attributes in C are exactly the ones in Z or less, then yes,
the expressions are equivalent.
3.

• If we consider the case in which there are more attributes in C than the ones in Z
then the expressions are equivalent since we cannot switch the projection and select
operators. (Π𝑧 𝜎𝑐 ≠ 𝜎𝑐 Π𝑧 ).
• Also, if we assume that the attributes in C are exactly the ones in Z or less, the
expressions are still not equivalent.
In this case we already have: Π𝑧 𝜎𝑐 = 𝜎𝑐 Π𝑧 . So in order to prove that the expressions
are not equivalent we only need to show that (𝑅 ∪ 𝑆) − 𝑆 ≠ Π𝑧 (𝑅 ∪ 𝑆) − Π𝑧 𝑆 .
Which is true because while applying the set difference we’re taking into
consideration all the attributes, but when projecting only on some of them we might
add more rows than what was supposed to be added. Because two rows might have
all the Z attributes equal but it doesn’t mean that all other attributes are also equal
so the set difference will change when projecting only on Z attributes.
Note that: (𝑅 ∪ 𝑆) − 𝑆 ⊇ Π𝑧 (𝑅 ∪ 𝑆) − Π𝑧 𝑆.
4. No, unless the tables have the same attributes then yes they are equivalent.
5. yes.
6. no, unless the decomposition is lossless which means that the first expression is included
in the second one.
Question3:
1.
SuperKeys: RI, RI combined with the other keys.
Candidate Keys: RI.
Introduction to databases Assignement 2

𝑀+ = {𝑀, 𝐺, 𝐻}
𝐺 + = {𝐺}
𝐻 + = {𝐻}
𝑅 + = {𝑅, 𝑀, 𝐵, 𝐺, 𝐻}
𝐼 + = {𝐼}
𝐵 + = {𝐵}
2.
L is not in BCNF since M and R are not superkeys.
BCNF Decomposition:
Step 1:
We have 𝐿(𝑀, 𝐺, 𝐻, 𝑅, 𝐼, 𝐵) with:
𝑀 → 𝐺𝐻 (Violates BCNF)
𝑅 → 𝑀𝐵
Step 2:
𝐿1 (𝑀, 𝐺, 𝐻)
𝑀 → 𝐺𝐻
𝐿2 (𝑀, 𝑅, 𝐼, 𝐵)
𝑅 → 𝑀𝐵 (Violates BCNF)
Step 3:
𝐿1 (𝑀, 𝐺, 𝐻)
𝑀 → 𝐺𝐻
𝐿2 (𝑀, 𝑅, 𝐵)
𝑅 → 𝑀𝐵
𝐿3 (𝑅, 𝐼)
Question4:
1.
Relation N:
Candidate Keys: 𝑁1 𝑎𝑛𝑑 𝑁3 .
Relation I:
Candidate Keys: 𝐼1 𝐼5 𝐼6 𝐼7 .
Introduction to databases Assignement 2

Relation Y:
Candidate Keys: 𝑌1 𝑎𝑛𝑑 𝑌6 .
2.
Relation N:
We have 𝑁(𝑁1 , 𝑁2 , 𝑁3 , 𝑁4 ) with:
𝑁1 → 𝑁2 , 𝑁3 , 𝑁4
𝑁3 → 𝑁1 , 𝑁2
Step 1: Making sure that all functional dependencies have singleton right-hand sides.
We get 𝑁(𝑁1 , 𝑁2 , 𝑁3 , 𝑁4 )
𝑁1 , 𝑁3 → 𝑁2
𝑁1 → 𝑁3
𝑁1 → 𝑁4
𝑁3 → 𝑁1
Step 2: Checking if we can eliminate functional dependencies that have two or more
attributes on the left hand-side.

𝑁1 + = {𝑁1 , 𝑁2 , 𝑁3 , 𝑁4 }
𝑁3 + = {𝑁1 , 𝑁2 , 𝑁3 , 𝑁4 }
We have 𝑁1 + 𝑐𝑜𝑛𝑡𝑎𝑖𝑛𝑠 𝑁3 𝑎𝑛𝑑 𝑁3 + 𝑐𝑜𝑛𝑡𝑎𝑖𝑛𝑠 𝑁1 so we can eliminate one of them.
We get:
𝑁1 → 𝑁2
𝑁1 → 𝑁3
𝑁1 → 𝑁4
𝑁3 → 𝑁1
Step 3: Checking whether we have any redundant functional dependencies.
Since we have no redundant functional dependencies then we get:
𝑁1 → 𝑁2
𝑁1 → 𝑁3
𝑁1 → 𝑁4
𝑁3 → 𝑁1
Relation I:
Introduction to databases Assignement 2

We have 𝐼(𝐼1 , 𝐼2 , 𝐼3 , 𝐼4 , 𝐼5 , 𝐼6 , 𝐼7 ) with:


𝐼1 → 𝐼2 , 𝐼3
𝐼1 → 𝐼4
𝐼2 → 𝐼4
𝐼3 → 𝐼4
Step 1: Making sure that all functional dependencies have singleton right-hand sides.
We get 𝐼(𝐼1 , 𝐼2 , 𝐼3 , 𝐼4 , 𝐼5 , 𝐼6 , 𝐼7 )
𝐼1 → 𝐼2
𝐼1 → 𝐼3
𝐼1 , 𝐼2 , 𝐼3 → 𝐼4
Step 2: Checking if we can eliminate functional dependencies that have two or more
attributes on the left hand-side.

𝐼1 + = {𝐼1 , 𝐼2 , 𝐼3 , 𝐼4 }
𝐼2 + = {𝐼2 , 𝐼4 }
𝐼3 + = {𝐼3 , 𝐼4 }
We have 𝐼1 + 𝑐𝑜𝑛𝑡𝑎𝑖𝑛𝑠 𝐼2 𝑎𝑛𝑑 𝐼3 so we can eliminate them both.
We get 𝐼(𝐼1 , 𝐼2 , 𝐼3 , 𝐼4 , 𝐼5 , 𝐼6 , 𝐼7 )
𝐼1 → 𝐼2
𝐼1 → 𝐼3
𝐼1 → 𝐼4
Step 3: Checking whether we have any redundant functional dependencies.
Since we have no redundant functional dependencies then we get:
𝐼1 → 𝐼2
𝐼1 → 𝐼3
𝐼1 → 𝐼4
Relation Y:
We have 𝑌(𝑌1 , 𝑌2 , 𝑌3 , 𝑌4 , 𝑌5 , 𝑌6 ) with:
𝑌1 → 𝑌2 , 𝑌3
𝑌1 → 𝑌4 , 𝑌5 , 𝑌6
𝑌3 → 𝑌4 , 𝑌5 , 𝑌6
Introduction to databases Assignement 2

𝑌6 → 𝑌1 , 𝑌2
Step 1: Making sure that all functional dependencies have singleton right-hand sides.
𝑌1 , 𝑌6 → 𝑌2
𝑌1 → 𝑌3
𝑌1 , 𝑌3 → 𝑌4
𝑌1 , 𝑌3 → 𝑌5
𝑌1 , 𝑌3 → 𝑌6
𝑌6 → 𝑌1
Step 2: Checking if we can eliminate functional dependencies that have two or more
attributes on the left hand-side.
Let’s start with 𝑌1 , 𝑌6 → 𝑌2 :

𝑌1 + = {𝑌1 , 𝑌2 , 𝑌3 , 𝑌4 , 𝑌5 , 𝑌6 }
𝑌6 + = {𝑌1 , 𝑌2 , 𝑌3 , 𝑌4 , 𝑌5 , 𝑌6 }
We have 𝑌1 + 𝑐𝑜𝑛𝑡𝑎𝑖𝑛𝑠 𝑌6 𝑎𝑛𝑑 𝑌6 + 𝑐𝑜𝑛𝑡𝑎𝑖𝑛𝑠 𝑌1 so we can eliminate one of them.
We get:
𝑌1 → 𝑌2
𝑌1 → 𝑌3
𝑌1 , 𝑌3 → 𝑌4
𝑌1 , 𝑌3 → 𝑌5
𝑌1 , 𝑌3 → 𝑌6
𝑌6 → 𝑌1
Let’s continue with 𝑌1 , 𝑌3 → 𝑌4 :

𝑌1 + = {𝑌1 , 𝑌2 , 𝑌3 , 𝑌4 , 𝑌5 , 𝑌6 }
𝑌3 + = {𝑌3 , 𝑌4 , 𝑌5 , 𝑌6 }
We have 𝑌1 + 𝑐𝑜𝑛𝑡𝑎𝑖𝑛𝑠 𝑌3 so we can eliminate it.
We get:
𝑌1 → 𝑌2
𝑌1 → 𝑌3
𝑌1 → 𝑌4
𝑌1 , 𝑌3 → 𝑌5
Introduction to databases Assignement 2

𝑌1 , 𝑌3 → 𝑌6
𝑌6 → 𝑌1
Let’s continue with 𝑌1 , 𝑌3 → 𝑌5 :

𝑌1 + = {𝑌1 , 𝑌2 , 𝑌3 , 𝑌4 , 𝑌5 , 𝑌6 }
𝑌3 + = {𝑌3 , 𝑌5 , 𝑌6 }
We have 𝑌1 + 𝑐𝑜𝑛𝑡𝑎𝑖𝑛𝑠 𝑌3 so we can eliminate it.
We get:
𝑌1 → 𝑌2
𝑌1 → 𝑌3
𝑌1 → 𝑌4
𝑌1 → 𝑌5
𝑌1 , 𝑌3 → 𝑌6
𝑌6 → 𝑌1
Same thing happens again with 𝑌1 , 𝑌3 → 𝑌6 so we get:
𝑌1 → 𝑌2
𝑌1 → 𝑌3
𝑌1 → 𝑌4
𝑌1 → 𝑌5
𝑌1 → 𝑌6
𝑌6 → 𝑌1
Step 3: Checking whether we have any redundant functional dependencies.
Since we have no redundant functional dependencies then we get:
𝑌1 → 𝑌2
𝑌1 → 𝑌3
𝑌1 → 𝑌4
𝑌1 → 𝑌5
𝑌1 → 𝑌6
𝑌6 → 𝑌1
3.
We have 𝐴(𝐴1 , 𝐴2 , 𝐴3 , 𝐴4 , 𝐴5 , 𝐴6 ) with:
Introduction to databases Assignement 2

𝐴1 + = {𝐴1 }
𝐴2 + = {𝐴1 , 𝐴2 , 𝐴4 , 𝐴5 , 𝐴6 }
𝐴3 + = {𝐴1 , 𝐴3 , 𝐴4 , 𝐴5 , 𝐴6 }
𝐴4 + = {𝐴1 , 𝐴4 , 𝐴6 }
𝐴5 + = {𝐴1 , 𝐴5 , 𝐴6 }
𝐴6 + = {𝐴6 }
SuperKeys: 𝐴2 𝐴3 , 𝐴2 𝐴3 combined with the other keys.
So, A isn’t in BCNF because 𝐴4 , 𝐴5 → 𝐴1 , 𝐴6 (violates BCNF)
We decompose them and we get:
𝐷1 (𝐴4 , 𝐴5 , 𝐴1 , 𝐴6 )
𝐴4 , 𝐴5 → 𝐴1 , 𝐴6
𝐷2 (𝐴4 , 𝐴5 , 𝐴2 , 𝐴3 )
𝐴2 , 𝐴3 → 𝐴4
𝐴2 , 𝐴3 → 𝐴5
Which is in BCNF which implies that it’s also lossless.
We can also check for dependency since we can verify 𝐴4 , 𝐴5 → 𝐴1 , 𝐴6 in 𝐷1 and also
𝐴2 , 𝐴3 → 𝐴4 and 𝐴2 , 𝐴3 → 𝐴5 in 𝐷2 .
4.

N I Y A

Is 3NF? Yes No Yes No

Is BCNF? Yes No Yes No

You might also like