DB Design Exercises
DB Design Exercises
DB Design Exercises
Contents
0.1 PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0.2 MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0.3 SQLServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1 ER Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.3 Closure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1/14
Exercises Database Design - 2023 /nvDieu
0.2 MySQL
1. Server: MySQL
2. IDE: WorkBench
0.3 SQLServer
1. Server: SQLSserver
2. IDE: SSMS
Exercise 1.1.2
Consider STUDENT entity, and the only attributes of student are student number and name. Let us suppose we have
another entity called HIGH SCHOOL — the high school from which the student graduated. For the HIGH SCHOOL
entity, we will record the high school name and the location (meaning city and state). Draw the ER diagram for it.
Exercise 1.1.3
If we have two entities, a PLANE and a PILOT, and describe the relationship between the two entities as
“A PILOT flies a PLANE.”
What should the relationship read from the side of the other entity?
Exercise 1.1.4
Suppose a college had one dormitory with many rooms. The DOMITORY entity, which is actually a “dormitory room”
entity since there is only one dorm. Dormitory has the attributes room number and singledouble (meaning there are
private rooms and double rooms). Let us suppose the STUDENT entity in this case contains the attributes student
number, student name, and cell telephone number. Draw the ER diagram linking the two entities. Name your
relationships.
Exercise 1.1.5
West Florida Mall
A new mall, West Florida Mall, just had its grand opening three weeks ago in Pensacola, Florida. This new mall is
attracting a lot of customers and stores. West Florida Mall, which is part of a series of malls owned by a parent company,
now needs a database to keep track of the management of the mall in terms of all its stores as well as the owners and
workers in the stores. Before we build a database for this system of malls, the first step will be to design an ER diagram
for the mall owner. We gathered the following initial user specifications about the mall, with which we can start creating
the ER diagram:
1. We need to record information about the mall and each store in the mall. We need to record the mall’s name and
address. A mall, at any point in time, must contain one or more stores.
2/14
Exercises Database Design - 2023 /nvDieu
2. For each store we will need to keep the following information: store number (which will be unique), the name of
the store, location of store (room number), departments, the owner of the store, and manager of the store. Each
store may have more than one department with each department having a manager. Each store will have only one
manager. Each store is owned by only one owner. Each store is located in one and only one mall.
3. A store manager can manage only one store. We must record information on the store manager—the name, Social
Security number, which store he or she is working for, and the salary.
4. The store owner is a person. We will record name, address, and of cell phone about the store owner. A store owner
must own at least one store and may own more than one.
Exercise 1.2.2
Map ERD exercise 1.1.2 to Relational Model
Exercise 1.2.3
Map ERD exercise 1.1.3 to Relational Model
Exercise 1.2.4
Map ERD exercise 1.1.4 to Relational Model
Exercise 1.2.5
Map ERD exercise 1.1.5 to Relational Model
a) A → B
b) AB → D
c) C → BDE
d) E → A
e) A → E
Exercise 2.1.2
Prove that r satisfies X → Y if and only if X is a key of π XY (r).
Exercise 2.1.3
Let r be a relation on R, with X a subset of R. Show that if π X (r) has the same number of tuples as r, then r satisfies
X → Y for any subset Y of R.
3/14
Exercises Database Design - 2023 /nvDieu
Exercise 2.1.4
Prove or disprove the following inference rules for a relation r(R) with W, X, Y, Z subsets of R.
a) X → Y and Z → W imply XZ → Y W .
b) XY → Z and Z → X imply Z → Y .
c) X → Y and Y → Z imply X → Y Z.
d) X → Y , W → Z , and Y ⊇ W imply X → Z.
Exercise 2.2.2
{ }
Consider F = AB → E, AG → J, BE → I, E → G, GI → H
Prove by Amstrong: F |= AB → GH
Exercise 2.2.3
{ }
Consider F = A → D, B → CE, E → H, D → E, E → C
Prove by Amstrong:
a) F |= B → H
b) F |= AB → CH
Exercise 2.2.4
{ }
Consider F = D → BK, AB → GK, B → H, CE → AG, H → E, K → G, EH → K, G → AH
Prove by Amstrong:
a) F |= AB → GH
b) F |= DE → AG
c) F |= BH → EK
2.3 Closure
Exercise 2.3.1
Show that for any set of FDs F , F + = (F + )+ .
Exercise 2.3.2
{ R(ABCDE) and set of functional dependencies:
Suppose }
F = A → BC, CD → E, B → D, E → A . Compute:
a) CDF+
b) EF+
Exercise 2.3.3
{ R(ABCDEK) and set of functional dependencies:
Suppose }
F = AB → C, BC → AD, D → E, CK → B . Compute:
a) BCKF+
b) CDF+
c) DF+
4/14
Exercises Database Design - 2023 /nvDieu
Exercise 2.3.4
{ R(ABCDEKGH) and set of functional dependencies:
Suppose }
F = A → BC, E → C, AH → D, CD → E, D → AEH, DH → BC . Compute:
a) AEF+
b) BCDF+
Exercise 2.3.5
Consider:
{ }
F1 = { AB → CD, A → BE, BH → DK, H → BC }
F2 = { AB → E, AG → J, BE → I, E → G, GI →}H
F3 = { A → D, B → CE, E → H, D → E, E → C }
F4 = D → BK, AB → GK, B → H, CE → AG, H → E, K → G, EH → K, G → AH
Compute:
a) AHF+1
b) ABF+2
c) BF+3
d) ABF+3
e) ABF+4
f) DEF+4
g) BHF+4
Exercise 2.3.6
{ }
Consider F = A → B, A → C, CD → E, B → D, E → A
Which of the following functional dependencies is NOT implied by the above set ?
a) CD → AC
b) BD → CD
c) BC → CD
d) AC → BC
Exercise 2.3.7
From Axiom 1, 2, 3 prove Axiom 4, 5 and 6.
Exercise 2.3.8
Prove that inference axioms 1, 2, and 3 are independent. That is, no one of them can be proved from the other two.
Exercise 2.3.9
R(ABCD)
{ having two FDs sets: }
F = { A → B, B → C, AB → D , }
G = A → B, B → C, A → C, A → D
Are the two sets equivalent ?
Exercise 2.3.10
R(ABCD)
{ having two FDs sets: }
F = { A → B, B → C, A → C },
G = A → B, B → C, A → D
Are the two sets equivalent ?
Exercise 2.3.11
R(ACDEH)
{ having two FDs sets: }
F = { A → C, AC → D, E}→ AD, E → H ,
G = A → CD, E → AH
Are the two sets equivalent ?
5/14
Exercises Database Design - 2023 /nvDieu
Exercise 2.3.12
R(ABCDE)
{ having two FDs sets: }
F = { A → BC, A → D, CD → E , }
G = A → BCE, A → ABD, CD → E
Are the two sets equivalent ?
Exercise 2.3.13
R(ABCDE)
{ having two FDs sets: }
F = { AB → C, A → B, B → C, }A → C ,
G = AB → C, A → B, B → C
Are the two sets equivalent ?
Exercise 2.3.14
{ }
Consider F = A → B, B → C, C → A, B → A, A → C
a) Find a minimum cover Fc of F by loop from right to left
b) Find a minimum cover Fc of F by loop from left to right
Exercise 2.3.15
{ }
Consider F = A → BC, B → C, A → B, AB → C
Find a minimum cover Fc of F
Exercise 2.3.16
{ }
Consider F = A → BC, CD → E, B → D, E → A
Find a minimum cover Fc of F
Exercise 2.3.17
{ }
Consider F = B → A, AD → BC, C → ABD
Find a minimum cover Fc of F
Exercise 2.3.18
{ R(ABC),
Consider }
F = { AB → C, A → B}
G = A → B, B → C
Exercise 2.3.19
{ }
Consider R(ABCDE) , F = AB → CD, B → CD, CD → AE, DE → AB, D → E
Compute Projected Functional Dependencies:
a) π R (ABC) (F )
1
b) π R (BCD) (F )
2
c) π R (CDE) (F )
3
d) π R (ADE) (F )
4
e) π R (BDE) (F )
5
f) π R (AE) (F )
6
g) π R (DE) (F )
7
6/14
Exercises Database Design - 2023 /nvDieu
Exercise 2.3.20
{ R(ABCDEGH) ,
Consider }
F = AB → CD, E → D, ABC → DE, E → AB, D → AG, ACD → BE
Compute Projected Functional Dependencies:
a) π R (ABCD) (F )
1
b) π R (DEGH) (F )
2
c) π R (CDE) (F )
3
d) π R (ADE) (F )
4
e) π R (BDE) (F )
5
f) π R (AE) (F )
6
g) π R (DE) (F )
7
2.4 Keys
Exercise 2.4.1
{ R(ABCDEH) with a set of FDs }
Consider
F = A → B, BC → D, E → C, D → A
What are the candidate keys of R
a) AE, BE
b) AE, BE, DE
c) AEH, BEH, BCH
d) AEH, BEH, DEH
Exercise 2.4.2
{ R(DEGHIJKLM N ) with a set of FDs
Consider }
F = DE → G, D → IJ, EH → KL, K → M, L → N
What is the key for R ?
a) EF
b) DEH
c) DEHKL
d) E
Exercise 2.4.3
{ R(ABCDEKGH) with a set of FDs
Consider }
F = ABC → DE, AB → D, DE → ABCK, E → C
Find all the candidate keys of R
Exercise 2.4.4
{ R(ABCDEGHK) with a set of FDs
Consider }
F = CD → A, EC → H, GHB → AB, C → D, EG → A, H → B, BE → CD, EC → B
Find all the candidate keys of R
7/14
Exercises Database Design - 2023 /nvDieu
{ }
f) R6 (ABCDE), F6 = AB → C, B → A, D → A
{ }
g) R7 (ABCDE), F7 = AB → C, C → D, D → A
{ }
h) R8 (ABCDE), F8 = AB → CD, CD → AE, D → A
{ }
i) R9 (ABCDE), F9 = D → A, BC → E, A → C
{ }
j) R10 (ABCDEG), F10 = AB → CG, G → D, B → D
{ }
k) R11 (ABCDE), F11 = E → D, C → B, A → E B → A, D → C
{ }
l) R12 (ABCDE), F12 = AC → B, BD → C, CE → D
m) R13 (ABCD), F13 = ∅
Exercise 2.5.2
{ }
Consider R(ABCD), F = A → C, B → D
a) Keys and Normal form?
b) Decompose R
Exercise 2.5.3
{ }
Consider R(ABCD), F = AC → D
a) Keys and Normal form?
b) Decompose R
Exercise 2.5.4
{ }
Consider R(ABCDE), F = AB → C, B → A, D → A
a) Keys and Normal form?
b) Decompose R
Exercise 2.5.5
{ }
Consider R(ABCDE), F = CD → A, EC → B, AD → C
a) Keys and Normal form?
b) Decompose R
Exercise 2.5.6
{ R(ABCDEGH),
Consider }
F = CD → A, EC → H, GHB → AB, C → D, EG → A, H → B, BE → CD, EC → B
a) Keys and Normal form ?
b) Decompose R
Exercise 2.5.7
{ }
Consider R(ABCD), F = A → B, B → C, D → B
a) Normal form of R ?
b) If R is not good, let try to find a good decomposition for R
Exercise 2.5.8
{ }
Consider R(ABCD), F = A → B, B → C, A → D, D → C
One decomposition ρ of R:
R1 (AB), F1
R2 (AC), F2
R3 (BD), F3
a) Fi ?
b) Keys and Normal form of Ri ?
8/14
Exercises Database Design - 2023 /nvDieu
Exercise 2.5.9
{ R(A B D E M N O P X Y Z V W ),
Consider }
F = D → XM N P E, M P N → EY ABO, M N → ZO, O → V, P → ABW , AB → P, N E → M P
One decomposition ρ of R:
R1 (DXM N P E), F1
R2 (M N P EY ABO), F2
R3 (M N ZO), F3
R4 (OV ), F4
R5 (P ABW ), F5
a) Fi ?
b) Keys and Normal form of Ri ?
c) Evaluate the quality of ρ (Normal form, Conserve information, Conserve FDs)
d) If ρ is not good, let make a improvement of ρ
Exercise 2.5.10
{ R(ABCDEGH),
Consider }
F = CD → A, EC → H, GHB → AB, C → D, EG → A, H → B, BE → CD, EC → B
Evaluate
{ the decomposition below (Normal form,
} Conserve information, Conserve FDs)
ρ = R1 (ABC), R2 (CDEG), R3 (EGH)
Exercise 2.5.11
Give an example of a relation in 3NF that has some prime attribute transitively dependent upon a key
Exercise 2.5.12
Let R1 and R2 be relation schemes with R1 ∩ R2 = X. Show that for any relation r(R1 R2 ) that satisfies X → R2 ,
r = π R1 (r) ▷◁ π R2 (r)
a) AB ↠ C
b) AB ↠ E
c) D ↠ C
d) AD ↠ C
e) C ↠ DE
Exercise 2.6.2
{ }
Let R(ABCDE), D = A ↠ BC, A ↠ E, E ↠ CD
Proving by MVDs axiom:
a) D |= A ↠ C
b) D |= A ↠ BD
c) D |= AC ↠ BD
d) D |= AC ↠ BE
e) D |= DE ↠ AC
f) D |= DE ↠ AB
9/14
Exercises Database Design - 2023 /nvDieu
Exercise 2.6.3
{ }
Let R(ABCDGH), D = A ↠ B, B ↠ GH, CD ↠ G
Proving by MVDs axiom:
a) D |= BC ↠ AD
b) D |= BC ↠ GH
c) D |= BC ↠ DG
d) D |= CD ↠ AB
e) D |= CD ↠ BG
f) D |= CD ↠ GH
Exercise 2.6.4
{ }
Let R(ABCGHI), D = A ↠ B, B ↠ HI, CG ↠ H
++
Compute XD :
a) A++
D
b) AG++
D
c) BG++
D
++
d) BCD
e) HG++
D
Exercise 2.6.5
Prove the correctness of inference axioms M1 and M2.
Exercise 2.6.6
Prove the correctness of inference axiom M3.
Exercise 2.6.7
We know axiom M7 is correct from Lemma 8.3
Prove the correctness of inference axiom M4 using axioms M3 and M7.
Exercise 2.6.8
Prove the correctness of inference axiom M5 using axioms M4.
Exercise 2.6.9
Prove the correctness of inference axiom M6 using axioms M1-M5 and M7
Exercise 2.7.2
{ }
Consider D = AB → E, AG → J, BE → I, E → G, GI → H
Prove by Tableau Chase test: D |= AB → GH
Exercise 2.7.3
{ }
Consider D = A → D, B → CE, E → H, D → E, E → C
Prove by Tableau Chase test:
a) D |= B → H
b) D |= AB → CH
10/14
Exercises Database Design - 2023 /nvDieu
Exercise 2.7.4
{ }
Consider D = D → BK, AB → GK, B → H, CE → AG, H → E, K → G, EH → K, G → AH
Prove by Tableau Chase test:
a) D |= AB → GH
b) D |= DE → AG
c) D |= BH → EK
Exercise 2.7.5
{ R(ABCDE) and set of functional dependencies:
Suppose }
D = A → BC, CD → E, B → D, E → A . Using Tableau Chase test to compute:
+
a) CDD
+
b) ED
Exercise 2.7.6
{ R(ABCDEK) and set of functional dependencies:
Suppose }
D = AB → C, BC → AD, D → E, CK → B . Using Tableau Chase test to compute:
+
a) BCKD
+
b) CDD
+
c) DD
Exercise 2.7.7
{ R(ABCDEKGH) and set of functional dependencies:
Suppose }
D = A → BC, E → C, AH → D, CD → E, D → AEH, DH → BC . Using Tableau Chase test to compute:
+
a) AED
+
b) BCDD
Exercise 2.7.8
Consider:
{ }
D1 = { AB → CD, A → BE, BH → DK, H → BC }
D2 = { AB → E, AG → J, BE → I, E → G, GI →}H
D3 = { A → D, B → CE, E → H, D → E, E → C }
D4 = D → BK, AB → GK, B → H, CE → AG, H → E, K → G, EH → K, G → AH
Using Tableau Chase test to compute:
+
a) AHD1
+
b) ABD 2
+
c) BD 3
+
d) ABD 3
+
e) ABD 4
+
f) DED4
+
g) BHD4
Exercise 2.7.9
{ }
Consider D = A → B, A → C, CD → E, B → D, E → A
Using Tableau Chase test to compute: Which of the following functional dependencies is NOT implied by the above
set ?
a) CD → AC
b) BD → CD
c) BC → CD
d) AC → BC
11/14
Exercises Database Design - 2023 /nvDieu
Exercise 2.7.10
{ }
Let R(ABCDE), D = A ↠ BC, A ↠ E, E ↠ CD
Using Tableau Chase test to compute:
a) D |= A ↠ C
b) D |= A ↠ BD
c) D |= AC ↠ BD
d) D |= AC ↠ BE
e) D |= DE ↠ AC
f) D |= DE ↠ AB
Exercise 2.7.11
{ }
Let R(ABCDGH), D = A ↠ B, B ↠ GH, CD ↠ G
Using Tableau Chase test to compute:
a) D |= BC ↠ AD
b) D |= BC ↠ GH
c) D |= BC ↠ DG
d) D |= CD ↠ AB
e) D |= CD ↠ BG
f) D |= CD ↠ GH
Exercise 2.8.2
Prove that if a relation r(R) satisfies the MVDs X ↠ Y1 , X ↠ Y2 ... X ↠ Yk , where R = XY1 Y2 ...Yk , then r
decomposes converse information onto the relation schemes XY1 , XY2 , ..., XYk .
Exercise 2.8.3
Let r(R) be a relation where R1 ⊆ R, R2 ⊆ R and R = R1 R2 . Prove that r = π R1 (r) ▷◁ π R2 (r) if and only if:
Count(π R ([X = x](r))) = Count(π R1 ([X = x](r))) × Count(π R2 ([X = x](r))) for every X-value x in r
Exercise 2.8.4
Prove that if relation r(R) satisfies X ↠ Y and Z = R − XY , then
π Z (σ X=x (r)) = π Z (σ XY =xy (r))
for every XY -value xy in r
Exercise 2.8.5
Let relation scheme R} and let W, X, Y, Z ⊆ R. Show that:
{
X ↠ Y , Z ⊆ W |= XW ↠ Y Z
Exercise 2.8.6
Prove the correctness of inference axiom M6 using axioms M1-M5 and M7
Exercise 2.8.7
} let X, Y, Z ⊆ R. Show that:
{ relation scheme R and
Let
X ↠ Y , XY → Z |= X → Z − Y
12/14
Exercises Database Design - 2023 /nvDieu
• Customers: Stores information about customers, such as name, address, phone number, and email.
• Products: Stores information about the products, such as name, price, quantity, and description.
• Orders: Stores information about orders, such as order date.
• Invoice: Stores information about the invoice, such as invoice date, amount, tax, and total value.
Request:
Exercise 3.0.2
Order and Delivery Management System: (considered by ChatGPT)
You are tasked with designing an ERD for a complex order and delivery management system for a global e-commerce
platform. This system handles orders for a wide range of products and manages deliveries across multiple regions.
Consider the following entities and relationships:
Entities:
1. Customer
2. Product
3. Order
4. Delivery
5. Warehouse
6. Shipping Carrier
7. Payment
8. Address
9. Region
Relationships:
Requirements:
3. Logical design.
4. Physical design.
Exercise 3.0.3
Restaurant Order and Delivery with Special Orders: (considered by ChatGPT)
a high-end restaurant’s order and delivery management system. This restaurant not only handles regular menu items but
also allows customers to place special orders with unique customization requests. Here are some additional complexities
to consider:
Entity:
1. Customer
2. Order
3. Menu Item
4. Special Order
5. Ingredient
6. Delivery Driver
7. Delivery Location
8. Table (for dine-in orders)
Relationships:
• Special orders can have multiple ingredients, and ingredients can be in multiple special orders.
• Some orders are for dine-in, and some are for delivery.
• Each delivery order is associated with one delivery driver and one delivery location.
Requirements:
14/14