DatabaseDesign 2023
DatabaseDesign 2023
2023
Strong Entity
Weak entity and Identifying Relationship
Weak Entity connected Weak Entity
Update Methodology
Mapping Weak Entity to Rational Database
2.6 Extensions with Binary Relationships
Attributes of Relationship
M:N Relationship
More Entity and Relationship
2.7 Recursive Relationship
Structural Constraints
Multiple Relationship
2.8 Mapping Recursive Relationship
2.9 Derived or Redundant Relationship
2.10 Enhanced EntityRelationship (EER) Model
3. Logical Design
3.1 Functional Dependencies
Definition
Notation
Satisfaction
Integrity Constraint
Inference
3.2 Amstrong’s Axioms
Amstrong’s Axioms
Lemma
Proof
3.3 Closure
Closure of FDs Set
Closure of Attribute Set
Algorithm
Lemma
Testing Membership
Covers
Minimum Covers
Algorithm
Projected FD
Algorithm
3.4 Keys
Definition
Algorithm
Remarkable
Algorithm
FDs by Keys
3.5 Normal Form
Definition
1NF
Fully dependent
Prime and nonprime attributes
2NF
Transitively Dependent
3NF Classic
3NF Modern
Lemma
BCNF Classic
BCNF Modern
3.6 Database Normalization
Overview
Preserve Information
Tableau Test
Theorem
Preserve Dependencise
Testing Preserve Dependencies
Decomposition Algorithm
Synthesis Algorithm
3.7 Multivalued Dependencies
Overview
Definition
Lemma
Trivial MVDs
Theorem
Test MVDs
3.8 Axioms for MVDs
MVDs Alone
FDs and MVD
Embedded MVDs
Embedded JD
4. Physical Design
4.1 Overview
4.2 Conceptual to Physical
Problem
ERD
Relational Model
Normal Form
Normalization
Customize Name
Foreign Keys
SQL Script
4.3 Denormalization
4.4 Customized data views
4.5 Indexes
• One-to-One (1:1) one entity is associated with one other entity and vice versa
• Many-to-One (M:1) many entity are associated with one another entity
• One-to-Many (1:M)
• Many-to-Many (M:N)
• Participation (Full/Partial)
Full (doube lines): All entity associated with another entity
Partial (single line): Not every entity associated with another entity
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Constraints of relationships 17/248
Pattern 1
1(full):1 Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Patterns and Relationships 18/248
Pattern 1
M(full):1 Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Patterns and Relationships 19/248
Pattern 2
1(partial):1 Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Patterns and Relationships 20/248
Pattern 2
M(partial):1 Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Patterns and Relationships 21/248
Pattern 3
1(full):M Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Patterns and Relationships 22/248
Pattern 3
M(full):N Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Patterns and Relationships 23/248
Pattern 4
1(partial):M Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Patterns and Relationships 24/248
Pattern 4
M(partial):N Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Patterns and Relationships 25/248
Summary of the notation for ER diagrams
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Summary of the notation 26/248
Summary of the notation for ER diagrams
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Summary of the notation 27/248
COMPANY database - Using Tool to draw ERD
Nguyễn Văn Diêu 2. Conceptual Design :: ER Conceptual Model :: Database Example 28/248
ER Design Methodology
• Step 1. Select one primary entity from the database requirements description and
show attributes to be recorded for that entity. Label key if appropriate, and show
some sample data.
• Step 2. Use structured English for entities, attributes, and keys to describe the
database.
• Step 3. Examine attributes in the primary entity (possibly with user assistance)
to find out if information about one of the attributes is to be recorded.
• Step 3a. If information about an attribute is needed, then make the attribute an
entity, and then
• Step 3b. Define the relationship back to the original entity.
• Step 4. If another entity is appropriate, draw the second entity with its attributes.
Repeat step 2 to see if this entity should be further split into more entities.
Consider a model for a simplified airport where PASSENGERS and FLIGHTS are to
be recorded. Suppose the attributes of PASSENGERS are name, luggage_pieces
and frequent_flier_no. Suppose the attributes for FLIGHT are flight_no,
destination, arrive_time and depart_time. Draw the ER diagram.
ER Design Methodology:
Step 1. Select one primary entity from the database requirements description and
show attributes to be recorded for that entity. Label keys if appropriate and show some
sample data.
Suppose we choose PASSENGERS as our primary entity. PASSENGERS has the
following attributes: frequent_flier_no, name [frst, middle, last], luggage_pieces.
Step 2. Use structured English for entities, attributes, and keys to describe the elicited
database.
Step 3. Examine attributes in the primary entity (possibly with user assistance) to find
out if information about one of the attributes is to be recorded.
Step 6. State the exact nature of the relationships in structured English from all sides,
such as, if a relationship is A:B::1:M, then there is a relationship from A(1) to B(M)
and from B(M) back to A(1).
Step 7. Present the “as designed” database to the user complete with the English for
entities, attributes, keys, and relationships. Refine the diagram, as necessary.
Step 8. Show some sample data.
Mapping rule 1: Mapping strong entities. Develop a new table (relation) for each
strong entity and make the indicated key of the strong entity the primary key of the
table. If more than one candidate key is indicated on the ER diagram, choose one for
the primary key. Call this table, TABLE1.
Mapping rule 2: Mapping atomic attributes. For entities with atomic attributes, map
the entities to a table and form columns for each atomic attribute. Here we’d map the
atomic attributes associated with TABLE1 into it.
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Entity 36/248
Mapping Entity to Relation
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Entity 37/248
Mapping Entity to Relation
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Entity 38/248
Mapping Entity to Relation
Mapping rule 4: Mapping multivalued attributes. Form a separate table for the
multivalued attribute. Record a row for each value of the multivalued attribute
together with the key from the original table. The key of the new table will be the
concatenation of the multivalued attribute plus the key of the owner entity. Remove
the multivalued attribute from the original table.
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Entity 40/248
Mapping Entity to Relation
Mapping rule 5: Mapping binary M:N relationships. For each M:N relationship,
create a new table (relation) with the primary keys of each of the two entities (owner
entities) related in the M:N relationship. The primary key of this new table will be the
concatenated keys of the owner entities. Include any attributes the M:N relationship
may have in this new table.
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 42/248
Mapping Relationship to Relation
Mapping rule 6: Mapping a binary 1:1 relationship when one side of the relationship
has full participation and the other has partial participation. When one of the sides of
the relationship has full participation and the other has partial participation, then store
the primary key of the side with the partial participation constraint on the side with
the full participation constraint as a foreign key. Include any attributes on the
relationship on the same side to which the key was added.
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 44/248
Mapping Relationship to Relation
AUTOMOBILE(vehicle_id, make,
body_style, color, year,
student_number)
STUDENT(student_number,
name.first, name.mid,
name.last, address)
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 45/248
Mapping Relationship to Relation
Mapping rule 7: Mapping a binary 1:1 relationship when both sides have partial
participation constraints.
When both sides have partial participation constraints in a binary 1:1 relationship, the
relationships can be mapped in one of two ways.
Mapping rule 7A: Select either one of the relations to store the key of the other.
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 46/248
Mapping Relationship to Relation
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 47/248
Mapping Relationship to Relation
Mapping rule 7B:. Depending on the semantics of the situation, you can create a
new relation to house the relationship to contain the key of the two related entities.
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 48/248
Mapping Relationship to Relation
Mapping rule 8: Mapping a binary 1:1 relationship when both sides have full
participation constraints. Use the semantics of the relationship to select which of the
relations should contain the key of the other. If this choice is unclear, then use
mapping rule 7B.
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 49/248
Mapping Relationship to Relation
Mapping rule 9: Mapping binary 1:N relationships when the N side has full
participation. Include the key of the entity on the 1 side of the relationship as a foreign
key on the N side.
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 50/248
Mapping Relationship to Relation
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 51/248
Mapping Relationship to Relation
Mapping rule 10: Mapping binary 1:N relationships when the N side has partial
participation. This situation would be handled just like a binary M:N relationship with
a separate table for the relationship. The key of the new relation would consist of a
concatenation of the keys of the related entities. Include any attributes on the
relationship on this new table.
Nguyễn Văn Diêu 2. Conceptual Design :: Mapping to Relational Database :: Mapping Relationship 52/248
Strong Entity
Strong entities almost always have a unique identifer that is a subset of all the
attributes.
e.g.
Nguyễn Văn Diêu 2. Conceptual Design :: Weak Entity :: Strong Entity 53/248
Strong Entity
Sample data:
Nguyễn Văn Diêu 2. Conceptual Design :: Weak Entity :: Strong Entity 54/248
Weak Entity
Nguyễn Văn Diêu 2. Conceptual Design :: Weak Entity :: Weak entity and Identifying Relationship 55/248
Weak Entity
Nguyễn Văn Diêu 2. Conceptual Design :: Weak Entity :: Weak entity and Identifying Relationship 56/248
Weak Entity - Weak Entity
Nguyễn Văn Diêu 2. Conceptual Design :: Weak Entity :: Weak Entity connected Weak Entity 57/248
Methodology (+ Weak Entity)
Step 3. Examine attributes in the primary entity (possibly with user assistance) to find
out if information about one of the attributes is to be recorded.
Step 3a. If information about an attribute is needed, then make the attribute an
entity, and then
Step 3b. Define the relationship back to the original entity.
So, we add
Step 3c. If the new entity depends entirely on another entity for its existence, then
draw the entity as weak (double boxed) and show the connection to the identifying
entity as a double diamond. The participation of the weak entity in the relationship is
full. Dash underline the partial key identifier(s) in the weak entity.
Nguyễn Văn Diêu 2. Conceptual Design :: Weak Entity :: Update Methodology 58/248
Methodology (+ Weak Entity)
Step 4. If another entity is appropriate, draw the second entity with its attributes.
Repeat step 2 to see if any attributes should be further split into more entities.
Step 4a. If the additional entity or entities do not have candidate keys, then draw
them as weak entities (as explained in step 3c) and show the connection to an
identifying entity. The participation of the weak entity in the relationship is full or
mandatory. Dash or dot underline the partial key identifier(s) in the weak entity.
Nguyễn Văn Diêu 2. Conceptual Design :: Weak Entity :: Update Methodology 59/248
Mapping Weak Entity to Relational DB
Mapping Rule 11: Mapping weak entities. Develop a new table (relation) for each
weak entity. As is the case with the strong entity, include any atomic attributes from
the weak entity in the table.
If there is a composite attribute, include only the atomic parts of the composite
attribute and be sure to qualify the atomic parts in order not to lose information. To
relate the weak entity to its owner, include the primary key of the owner entity in the
weak relation. The primary key of the weak relation will be the partial key of the weak
entity concatenated to the primary key of the owner entity.
If a weak entity owns other weak entities, then the weak entity connected to the strong
entity must be mapped first. The key of the weak owner-entity has to be defined
before the “weaker” entity (the one furthest from the strong entity) can be mapped.
Nguyễn Văn Diêu 2. Conceptual Design :: Weak Entity :: Mapping Weak Entity to Rational Database 60/248
Mapping
EMPLOYEE(employee_id, fname,
minit, lname)
DEPENDENT(employee_id, dname,
insurance, birth_date)
HOBBY(employee_id, dname, type,
year_involved)
Nguyễn Văn Diêu 2. Conceptual Design :: Weak Entity :: Mapping Weak Entity to Rational Database 61/248
Attributes of Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: Extensions with Binary Relationships :: Attributes of Relationship 62/248
Change M:N Relationship
Change to:
• Intersection Weak Entity:
STUDENT-COURSE
• Attribute: grade
• Key: student_ID +
course_ID
• Relationship 1: Rel1
• Relationship 2: Rel2
Nguyễn Văn Diêu 2. Conceptual Design :: Extensions with Binary Relationships :: M:N Relationship 63/248
More Entity and Relationship
Update Methodology:
Step 4. If another entity is appropriate, draw the second entity with its attributes.
Repeat step 2 to see if this entity should be further split into more entities.
Step 5. Connect entities with relationships (one or more) if relationships exist.
Nguyễn Văn Diêu 2. Conceptual Design :: Extensions with Binary Relationships :: More Entity and Relationship 64/248
More Entity and Relationship
Te relationship between
INSTRUCTOR and COURSE is
teach; instructors teach many
courses, and a course is taught by
an instructor.
We add relationship teach.
Nguyễn Văn Diêu 2. Conceptual Design :: Extensions with Binary Relationships :: More Entity and Relationship 65/248
More Entity and Relationship
Nguyễn Văn Diêu 2. Conceptual Design :: Extensions with Binary Relationships :: More Entity and Relationship 66/248
Recursive Relationship
e.g.
Nguyễn Văn Diêu 2. Conceptual Design :: Recursive Relationship :: Structural Constraints 68/248
One to Many Recursive Relationship
e.g.
Nguyễn Văn Diêu 2. Conceptual Design :: Recursive Relationship :: Structural Constraints 69/248
Many to Many Recursive Relationship
e.g.
Nguyễn Văn Diêu 2. Conceptual Design :: Recursive Relationship :: Structural Constraints 70/248
Multiple Relationship
e.g.
Nguyễn Văn Diêu 2. Conceptual Design :: Recursive Relationship :: Multiple Relationship 71/248
Mapping Recursive Relationship
Mapping Rule 12: Mapping 1:N recursive relationships. Re-include the primary key of
the table with the recursive relationship in the same table, giving it some other role
name.
e.g.
PERSONNELL(emplye_id, fname, mname, lname, super_id)
Mapping Rule 13: Mapping M:N recursive relationships. Create a separate table for
the relationship (as in mapping rule 5).
Nguyễn Văn Diêu 2. Conceptual Design :: Enhanced EntityRelationship (EER) Model :: Subclasses of Subclasses 77/248
Subclasses of Subclasses
Nguyễn Văn Diêu 2. Conceptual Design :: Enhanced EntityRelationship (EER) Model :: Subclasses of Subclasses 78/248
Mapping rules to Relation
Nguyễn Văn Diêu 2. Conceptual Design :: Enhanced EntityRelationship (EER) Model :: Mapping rules 79/248
Union Types
Nguyễn Văn Diêu 2. Conceptual Design :: Union Types :: Mapping rules 86/248
Functional Dependencies Definition
Let:
• R(A1 , · · ·, An ) be a relational scheme,
• X and Y be subsets of {A1 , · · ·, An }
We say:
• X → Y, read ”X functionally determines Y” or ”Y functionally depends on X” if:
∀(t1 , t2 ) ∈ ∀r(R) :
Not possible: t1 (X) = t2 (X) but t1 (Y) ̸= t2 (Y)
• In the FD X → Y, X is called the Left side and Y called the Right side.
StudentID → StudentName
SubjectID → SubjectName
StudentID, SubjectID → Grades
• r satisfies FD X → Y
if ∀(t1 , t2 ) ∈ r(R) : t1 (X) = t2 (X) then t1 (Y) = t2 (Y)
• ”if ... then” statement, it can be satisfied either by:
1. t1 (X) ̸= t2 (X) or
2. t1 (Y) = t2 (Y)
• If r does not satisfy X → Y, the r violate X → Y.
• If we declared X → Y hold for R, then all instance r of scheme R will satisfy
X → Y.
• FD X → ∅ is trivially satisfied by any relation.
• FD ∅ → Y is satisfied by those relations in which every tuple has the same
Y − value.
Nguyễn Văn Diêu 3. Logical Design :: Functional Dependencies :: Integrity Constraint 91/248
Inference FD
Let R; A, B, C : attributes.
FD: A → B and B → C are known to hold in R.
We claim that A → C must also hold in R
Proof by Contradiction
Suppose r satisfies A → B and B → C,
but ∃(t1 , t2 ) ∈ r : t1 .A = t2 .A and t1 .C ̸= t2 .C
• if t1 .B ̸= t2 .B, then r violate A → B
• if t1 .B = t2 .B but t1 .C ̸= t2 .C then r violate B → C
Hence r must satisfy A → C ■
Direct Proof
∀(t1 , t2 ) ∈ ∀r(R) : t1 .A = t2 .A =⇒ t1 .B = t2 .B (A → B)
=⇒ t1 .C = t2 .C (B → C)
from FD definition =⇒ A → C ■
Nguyễn Văn Diêu 3. Logical Design :: Functional Dependencies :: Inference 92/248
Logically Inference
Nguyễn Văn Diêu 3. Logical Design :: Amstrong’s Axioms :: Amstrong’s Axioms 94/248
e.g.
Nguyễn Văn Diêu 3. Logical Design :: Amstrong’s Axioms :: Amstrong’s Axioms 95/248
Lemma
There are several other inference rules that follow from Amstrong’s Axioms
Lemma:
{ }
1. Union. X → Y, X → Z |= X → YZ
{ }
2. Pseudotransitivity. X → Y, WY → Z |= WX → Z
{ }
3. Decomposition. X → Y, Z ⊆ Y |= X → Z
Proof:
Union. Given X → Y |= X → XY (augment)
Given X → Z |= XY → YZ (augment)
{ }
By transitivity X → XY, XY → YZ |= X → YZ
Pseudotransitivity. Given X → Y |= WX → WY (augment)
Since given WY → Z |= WX → Z (transitivity)
Decomposition. Given Z ⊆ Y |= Y → Z (reflexivity)
Given X → Y, by transitivity, |= X → Z ■
Nguyễn Văn Diêu 3. Logical Design :: Closure :: Closure of FDs Set 100/248
e.g.
{ }
Let R(ABC) and F = A → B, B → C . Then F+ consists of all those dependencies
X → Y such that either
1. X contains A e.g., ABC → AB, AB → BC, or A → C,
2. X contains B but not A, and Y does not contain A e.g., BC → B, B → C, or
B → ∅, and
3. X → Y is one of the three dependencies C → C, C → ∅, or ∅ → ∅.
Nguyễn Văn Diêu 3. Logical Design :: Closure :: Closure of FDs Set 101/248
Closure of Attribute Set
Let:
• R be an attributes set.
• F be a functional dependencies set hold on R.
• X be a subset of R.
We define X+
F is the closure of X (with respect of F) is the set of attributes A such
that X → A can be logically implied from
{ F (by FD definition).
}
X+F = A | F |= X → A
e.g. { }
R(ABCD) , F = B → D, A → B, C → B
A+
F = ABD
Nguyễn Văn Diêu 3. Logical Design :: Closure :: Closure of Attribute Set 102/248
Algorithm
• X → X+F
• Z ⊆ X+
F , then X → Z
Proof: X → Z:
Suppose ∃(t1 , t2 ) : t1 .X = t2 .X, but t1 .Z ̸= t2 .Z
So ∃ A ∈ Z : t1 .A ̸= t2 .A. That is contradiction with closure set definition, because of
A ∈ Z ∈ X+
F ■
Similarly with X → X+
F ■
Let X → Y and F
Determine F |= X → Y ? We have three methods:
1. Using FD definition
2. Using Amstrong’s axioms
3. Test if X → Y ∈ F+
In the 3th method, F+ can be very lager
How to show X → Y ∈ F+ without generating all of F+
Algorithm:
1. X+
F
2. if Y ⊆ X+
F then F |= X → Y
if Y ⊈ XF then F |=
+
X → Y
Definition:
• Two FDs F and G over R are equivalent if F+ = G+
• Denote F ≡ G
• If F ≡ G, then F is a cover for G
Test whether F and G are equivalent:
• Step 1: F |= G
− Test every g : X → Y ∈ G is g ∈ F+
− g : X → Y ∈ G, compute X+
F
− If Y ⊆ X+
F , then g ∈ F , if not: g ∈
+ / F+
− If ∃ g ∈ G, ∈
/ F+ , then surely F+ ̸= G+
• Step 2: G |= F
Analogous manner Step 1:, test every f ∈ F is f ∈ G+
Nguyễn Văn Diêu 3. Logical Design :: Closure :: Covers 108/248
e.g.
{ }
F = { A → BC, A → D, CD → E }
G = A → BCE, A → ABD, CD → E
F≡G?
Step 1: F |= G.
A → BCE: A+ F = ABCDE ⇒ F |= A → BCE
A → ABD: A+ F = ABCDE ⇒ F |= A → ABD
CD → E: CD+ F = CDE ⇒ F |= CD → E
Step 2: G |= F.
A → BC: A+ G = ABCED ⇒ G |= A → BC
A → D: AG = ABCED ⇒ G |= A → D
+
CD → E: CD+ G = CDE ⇒ G |= CD → E
F≡G■
Definition
• F have many cover sets, its equivalent to F
• We define a set Fc is a minimal cover of F if:
R, F ; R1 : Attributes Set.
F1 = projected FDs of F on R1 ,
denote F1 = π R1 (F):
• F1 follow from F and
• Involve only attributes of R1 .
Input: R , F.
Output: All keys of R.
Method: Computing a sequence steps:
1. Generate all subsets of R, not ∅ set. Sorting it by ascending.
2. Computing closure those sets.
3. Only keep the sets, such that its closure equal R.
4. Remove the sets, it contains any other sets in list.
5. All sets remain are the all keys of relation scheme R.
Input: Q , F.
Output: All keys on Q.
Method: Computing a sequence steps:
1. L : attributes in the left side of FDs
R : attributes in the right side of FDs
NF = Q − (L + R) : attributes do not in FDs
OL = L − R : attributes only in left side of FDs
LR = L ∩ R : att. both in the left side and right side of FDs
2. Generate all subsets of LR including ∅.
Sorting it by ascending.
3. Add NF and OL into subsets above.
4. Computing closure for all subsets.
Decide the keys like general algorithm.
R , F,
K1 , K2 , · · · Kn : keys of R, then we have FDs:
K1 → R, or K1 → (R − K1 )
···
Kn → R, or Kn → (R − Kn )
e.g. { }
R(ABCDE) , F = AB → CD, D → E, BC → A
Two keys: K1 = AB, K2 = BC
Then, there are FDs logically implied by keys:
AB → CDE
BC → ADE
• Base on Keys checking system of DBMS, we have a concept to check all FDs on
relation.
• This concept is call Normal Form.
Relation Gender, shown below, is not in 1NF because it contains values that are sets
of atomic values.
Gender(Name, Sex)
⋉GateAssign
PilotAssign⋊
• Given R , F;
X, Y ⊆ R
• Y is called fully dependent upon X if:
1. X → Y ∈ F+
′ ′
2. ∄ X ⊊ X : X → Y ∈ F+
{ }
e.g. F = Flight, Day → Pilot, Gate; Flight → Gate
Gate is not fully dependent upon {Flight, Day}.
Pilot is fully dependent upon {Flight, Day}.
Nguyễn Văn Diêu 3. Logical Design :: Normal Form :: Fully dependent 133/248
Prime and nonprime attributes
• Given R , F
• A is an attribute in R
• A is prime in R with respect to F if A is contained in some key of R.
• Otherwise A is nonprime in R.
e.g. Assign(Flight, Day, Pilot, Gate)
with F = {Flight, Day → Pilot; Flight → Gate}
Key: {Flight, Day}
Prime: Flight and Day.
Nonprime: Pilot and Gate.
Nguyễn Văn Diêu 3. Logical Design :: Normal Form :: Prime and nonprime attributes 134/248
Second normal form (2NF)
• R,F
• X ⊆ R, A ∈ R
• A : transitively dependent upon X in R if there is a Y ⊆ R with:
• X → Y ∈ F+
• Y ↛ X ∈ F+
• Y → A ∈ F+
• A∈/ XY
Nguyễn Văn Diêu 3. Logical Design :: Normal Form :: Transitively Dependent 137/248
e.g.
Nguyễn Văn Diêu 3. Logical Design :: Normal Form :: Transitively Dependent 138/248
Third Normal Form (3NF)
Classic Definition
R is in third normal form (3NF) if:
• It is in 1NF, and
• no nonprime attribute in R is transitively dependent upon a key of R.
Nguyễn Văn Diêu 3. Logical Design :: Normal Form :: 3NF Classic 139/248
e.g.
Nguyễn Văn Diêu 3. Logical Design :: Normal Form :: 3NF Classic 140/248
Third Normal Form (3NF)
Modern Definition
R is in third normal form (3NF) if:
• It is in 1NF, and
• Whenever X → Y is a nontrivial FD in F+ , either
• X is a superkey, or
• Each B ∈ Y is a member of some key of R
Nguyễn Văn Diêu 3. Logical Design :: Normal Form :: 3NF Modern 141/248
Lemma 3NF ⇒ 2NF
R is not in 2NF ⇒ exists non-prime attribute A is not fully dependent upon key
′
K ⊆ R. So that ∃ K ⊊ K:
′
• K → A ∈ F+ and because of
′
• K ↛ K ∈ F+
′
• A∈/ K=K ∪K
Therefore A is transitively dependent upon key K, so that R is not in 3NF. ■
Classic Definition
R : Boyce-Codd normal form (BCNF) if:
• It is in 1NF, and
• No attribute in R is transitively dependent upon a key of R.
Nguyễn Văn Diêu 3. Logical Design :: Normal Form :: BCNF Classic 143/248
Boyce-Codd Normal Form (BCNF)
Modern Definition
R : Boyce-Codd normal form (BCNF) if:
• It is in 1NF, and
• for every Y ⊆ R and for every attribute A ∈ (R − Y)
• if Y → A, then Y → R
• That is, if Y non-trivially determines any attribute of R, then Y is a superkey for R.
Nguyễn Văn Diêu 3. Logical Design :: Normal Form :: BCNF Modern 144/248
Overview
r = π R1 (r) ⋊
⋉ π R2 (r) ⋊
⋉ ··· ⋊
⋉ π Rk (r)
In general:
r ⊆ π R1 (r) ⋊
⋉ π R2 (r) ⋊
⋉ ··· ⋊
⋉ π Rk (r)
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Preserve Information 147/248
Tableau Test for Preserve Information
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 149/248
e.g.
{ }
R(ABCD) , F = {A → B, B → C, CD → A }
Decomposed into R1 (AD), R2 (AC), R3 (BCD)
Preserve information testing.
The initial tableau:
A B C D
R1 (AD) 0 1 1 0
R2 (AC) 0 2 0 2
R3 (BCD) 3 0 0 0
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 150/248
e.g. (cont.)
A B C D
R1 (AD) 0 1 1 0
R2 (AC) 0 1 0 2
R3 (BCD) 3 0 0 0
{ }
F = A → B, B → C, CD → A
Apply B → C to equate 1, 0. Chosing 0 as the representative symbol (Figure below).
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 151/248
e.g. (cont.)
A B C D
R1 (AD) 0 1 0 0
R2 (AC) 0 1 0 2
R3 (BCD) 3 0 0 0
{ }
F = A → B, B → C, CD → A
Apply CD → A for row 1 and row 3, to equate 0, 3. Chosing 0 as the representative
symbol (Figure below).
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 152/248
e.g. (cont.)
A B C D
R1 (AD) 0 1 0 0
R2 (AC) 0 1 0 2
R3 (BCD) 0 0 0 0
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 153/248
e.g.
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 154/248
e.g. (cont.)
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 155/248
e.g.
{ }
R(ABCDE), F = A → C, B → C, C → D, DE → C, CE → A ,
R1 (AD), R2 (AB), R3 (BE), R4 (CDE), R5 (AE)
The initial tableau:
A B C D E
R1 (AD) 0 1 1 0 1
R2 (AB) 0 0 2 2 2
R3 (BE) 3 0 3 3 0
R4 (CDE) 4 4 0 0 0
R5 (AE) 0 5 5 5 0
Apply A → C for rows: 1, 2, 5 to equate 1, 2, 5. Choosing 1 as the representative
symbol (Figure below).
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 156/248
e.g. (cont.)
A B C D E
R1 (AD) 0 1 1 0 1
R2 (AB) 0 0 1 2 2
R3 (BE) 3 0 3 3 0
R4 (CDE) 4 4 0 0 0
R5 (AE) 0 5 1 5 0
{ }
F= A → C, B → C, C → D, DE → C, CE → A
Apply B → C for rows: 2, 3 to equate 1, 3. Choosing 1 as the representative symbol.
(Figure below)
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 157/248
e.g. (cont.)
A B C D E
R1 (AD) 0 1 1 0 1
R2 (AB) 0 0 1 2 2
R3 (BE) 3 0 1 3 0
R4 (CDE) 4 4 0 0 0
R5 (AE) 0 5 1 5 0
{ }
F= A → C, B → C, C → D, DE → C, CE → A
Apply C → D for roes: 1, 2, 3, 5 to equate 0, 2, 3, 5. The result symbol must be 0.
(Figure below)
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 158/248
e.g. (cont.)
A B C D E
R1 (AD) 0 1 1 0 1
R2 (AB) 0 0 1 0 2
R3 (BE) 3 0 1 0 0
R4 (CDE) 4 4 0 0 0
R5 (AE) 0 5 1 0 0
{ }
F= A → C, B → C, C → D, DE → C, CE → A
Apply DE → C for rows: 3, 4, 5 to equate 1 with 0.
(Figure below)
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 159/248
e.g. (cont.)
A B C D E
R1 (AD) 0 1 1 0 1
R2 (AB) 0 0 1 0 2
R3 (BE) 3 0 0 0 0
R4 (CDE) 4 4 0 0 0
R5 (AE) 0 5 0 0 0
{ }
F= A → C, B → C, C → D, DE → C, CE → A
Apply CE → A for rows: 3, 4, 5 to equate 3, 4, 0 must be with 0.
(Figure below)
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 160/248
e.g. (cont.)
A B C D E
R1 (AD) 0 1 1 0 1
R2 (AB) 0 0 1 0 2
R3 (BE) 0 0 0 0 0
R4 (CDE) 0 4 0 0 0
R5 (AE) 0 5 0 0 0
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 161/248
e.g. (cont.)
A B C D E
R1 (AD) 0 1 1 0 1
R2 (AB) 0 0 1 0 2
R3 (BE) 0 0 0 0 0
R4 (CDE) 0 4 0 0 0
R5 (AE) 0 5 0 0 0
The third row has all 0. Preserve information decomposition ■
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Tableau Test 162/248
Preserve Information Decomposition Theorem
If (R1 ∩ R2 ) → (R1 − R2 ) ∈ F+ .
Result has the second row to be all 0.
R1 ∩ R2 R1 − R2 R2 − R1
row for R1 0···0 0···0 1···1
row for R2 0···0 0···0 0···0
If (R1 ∩ R2 ) → (R2 − R1 ) ∈ F+ .
Result has the first row to be all 0.
R1 ∩ R2 R1 − R2 R2 − R1
row for R1 0···0 0···0 0···0
row for R2 0···0 2···2 0···0
We has ρ Preserve information decomposition ■
A B C
1 1 1
2 1 2
π AB (r) π BC (r)
A B B C
1 1 1 1
2 1 1 2
A B C
1 1 1
1 1 2
2 1 1
2 1 2
This natural join is proper superset of r.
Preserve Dependencies
R , F.
{ }
R decomposed into ρ = R1 , R2 , · · · , Rn .
Decomposition ρ preserve F if the union of all the dependencies in π Ri (F), for i = 1..n
logically implies all the dependencies in F:
{ }
π R1 (F) ∪ π R2 (F) ∪ · · · ∪ π Rn (F) |= F, aka
∪
n
π Ri (F) |= F
i=1
Note: The converse is always true; F always implies all its projections, and therefore
implies their union.
∪
n
F |= π Ri (F)
i=1
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Preserve Dependencise 168/248
e.g.
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Preserve Dependencise 169/248
e.g. (cont.)
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Preserve Dependencise 170/248
Testing Preserve Dependencies
R , F , ρ = {R1 , · · · , Rn }.
Easy to test ρ preserves F by:
1. Computing Fi = π Ri (F+ ).
∪
n
2. Test whether: Fi |= F ?
i=1
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Testing Preserve Dependencies 171/248
e.g.
{ }
R(ABCD) , F = A → B, B → C, C → D, D → A . Decomposition
{ }
ρ = R1 (AB), R2 (BC), R3 (CD)
Project F+ onto Ri , we get result:
{ }
F1 = A → B, B → A ,
{ }
F2 = B → C, C → B ,
{ }
F3 = C → D, D → C
∪
3
So Fi |= F
i=1
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Testing Preserve Dependencies 172/248
Preserve Information Decomposition into BCNF
Decomposition Algorithm
Input: R0 , F0 .
Output: A decomposition of R0 into a collection of relations, all of which are in BCNF.
Method: R = R0 and F = F0 .
Apply recursively < R, F >.
1. If R is in BCNF, return R. Done.
2. If R violated BCNF by X → Y (X is not a super key), decomposition R into
R1 (X+F ) and R2 (X ∪ (R − XF )).
+
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Decomposition Algorithm 173/248
e.g.
Instock(Product,
{ Category, Supply, Date, Quantity), with
F = Product → Category; Category
} → Supply;
Product, Date → Quantity
Key = {Product, Date} and Instock is in 1NF.
1. R = Instock
R violated BCNF
{ by Product → Category}
+
Product = Product, Category, Supply
R1 (Product,
{ Category, Supply), }
F1 = Product
{ → } Category; Category → Supply
Key = Product , violated BCNF by Category → Supply
R2 (Product
{ ∪ (R − Product+ )), R}2 (Product, Date, Quantity)
F2 = Product,
{ Date →} Quantity
Key = Product, Date , it is in BCNF.
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Decomposition Algorithm 174/248
e.g. (cont.)
2. R1 (Product,
{ Category, Supply) }
F1 = Product
{ →} Category; Category → Supply
Key = Product { , violated BCNF } by Category → Supply
Category+ = Category, Supply
R11 (Category,
{ Supply) }
F11 = {Category → } Supply
Key = Category , it is in BCNF.
R12 (Product,
{ Category) }
F12 = {Product → } Category
Key = Product , it is in BCNF.
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Decomposition Algorithm 175/248
e.g. (cont.)
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Decomposition Algorithm 176/248
e.g. (cont.)
R({
PCSDQ); Key = PD; 1NF }
F = P → C; C → S; PD → Q
P→C
R1 (PCS
{ ); Key = P; 2NF
} R2 (PDQ); Key
F1 = P → C; C → S { = PD;}BCNF
F2 = PD → Q
C→S
Notice: This algorithm decomposition into BCNF, its preserve information but not
sure about preserve FDs.
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Decomposition Algorithm 177/248
Preserve Information Decomposition into 3NF
Synthesis Algorithm
It decompose into 3NF Relations With preserve information and dependency.
Input: R , F
Output: Decomposition ρ, each of which is in 3NF. It has preserve information and
dependency.
Method: Perform the following steps:
1. Find a minimum cover of F, say Fc .
2. For each X → A ∈ Fc , use XA as the scheme of one of the relations in the
decomposition.
3. If none of the relation schemes from Step 2 is a superkey of R, add another
relation whose scheme is a key of R.
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Synthesis Algorithm 178/248
e.g.
{ }
R(ABCDE) , F = AB → C, C → B, A → D
F is also a minimum cover. So we have:
R1 (ABC) , R2 (BC) , R3 (AD).
Not to use a relation whose is a proper subset of another relation, so we can drop R2 .
R has two keys: K1 = ABE and K2 = ACE.
Neither of these keys is a subset of the schemes chosen so far. Thus, we must add one
of them, say R4 (ABE).
The final decomposition of R is thus:
{ }
R1 (ABC); F1 = { AB → C, } C→B ; 3NF
R2 (BC); F2 = { C → B }; BCNF
R3 (AD); F3 = A → D ; BCNF
R4 (ABE); F4 = ∅; BCNF
Nguyễn Văn Diêu 3. Logical Design :: Database Normalization :: Synthesis Algorithm 179/248
Overview
∗ (n, i, d) ∈ Supply: supply name n supplied item i and can use delivery type t for
that item.
∗ There is no FDs Name → Item or Name → Delivery on Supply,
yet Supply decomposes losslessly onto:
(Name, Item) and (Name, Delivery).
Nguyễn Văn Diêu 3. Logical Design :: Multivalued Dependencies :: Overview 180/248
Overview (cont.)
SupItem ⋊
⋉ SupDeli (Name Item Delivery)
Amazon Laptop Moto
Amazon Laptop Pick-Up
Amazon Washer Moto
Amazon Washer Pick-Up
McD Hamb Drone
McD Hamb Scooter
And join the two projections, we do not get back original instance.
r (R: X Y Z) r (R: X Y Z)
t1 : 1 1 1 t1 : x y z
t2 : 1 2 2 t2 : x y’ z’
t3 : 1 1 2 t3 : x y z’
t4 : 1 2 1 t4 : x y’ z
Note 1: The X ↠ Y says that the relationship between X and Y is independent of the
relationship between X and (R − Y).
r(R : ABCD) shown below satisfies the AB ↠ BC, hence it satisfies the AB ↠ D,
AB ↠ C and AB ↠ ABC
r (R: A B C D)
t1 : 1 1 1 1
t2 : 1 1 2 2
t3 : 1 1 1 2
t4 : 1 1 2 1
t5 : 1 2 2 1
t6 : 2 1 1 2
Definition
− R and X, Y ⊆ R
− MVD X ↠ Y is trivial if any relation r(R) satisfies X ↠ Y.
− So that
• Y ⊆ X or
• XY = R
Nguyễn Văn Diêu 3. Logical Design :: Multivalued Dependencies :: Trivial MVDs 190/248
Theorem
R, X ⊆ R, Y ⊆ R, Z = R − (XY)
r(R) satisfies the X ↠ Y {
r1 : R1 (XY)
⇔ r(R) reserve information decomposition into Proof
r2 : R2 (XZ)
1 ”⇒”: r : X ↠ Y ⇒ r = r1 ⋊ ⋉ r2
{
r ⊆ r1 ⋊
⋉ r2 ,
i.e. r : X ↠ Y ⇒
r1 ⋊
⋉ r2 ⊆ r
1.a r ⊆ r1 ⋊⋉ r2
i.e. ∀t ∈ r ⇒ t ∈ r1 ⋊⋉ r2 . This is evident without to MVD:
∀t ∈ r
t1 = t.XY ⇒ t1 ∈ π XY (r)
⇒ t1 ⋊ ⋉ t2 ∈ π XY (r) ⋊
⋉ π XZ (r)
t2 = t.XZ ⇒ t2 ∈ π XZ (r)
Since t = t1 ⋊⋉ t2 ⇒ t ∈ r1 ⋊ ⋉ r2 .
1.b r1 ⋊⋉ r2 ⊆ r
i.e ∀t ∈ r1 ⋊
⋉ r2 ⇒{ t ∈ r.
∃t1 ∈ r1 ,
∀t ∈ r1 ⋊⋉ r2 ⇒ : t = t1 ⋊
⋉ t2
∃t2 ∈ r2
t.XY = t1 ,
i.e. t.XZ = t2 ,
t1 .X = t2 .X
Nguyễn Văn Diêu 3. Logical Design :: Multivalued Dependencies :: Theorem 192/248
Theorem (cont.)
So we have:
t.X = t1 .X = t2 .X, (1)
t.Y = t1 .Y, (2)
t.Z = t2 .Z (3)
2 ”⇐”: r = r1 ⋊
⋉ r2 ⇒ r : X ↠ Y
∀(t1 , t2 ) ∈ r : t1 .X = t2 .X
∃t′1 ∈ (r1 = π XY (r)) : t′1 = t1 .XY (1)
∃t′2 ∈ (r2 = π XZ (r)) : t′2 = t2 .XZ (2)
Since r = r1 ⋊
⋉ r2 , so:
∃t ∈ r : t = t′1 ⋊
⋉ t′2
So that,
since (1): t.XY = t′1 = t1 .XY (3)
since (2): t.XZ = t′2 = t2 .XZ (4)
(3) ⇒ t.X = t1 .X, t.Y = t1 .Y (5)
(4) ⇒ t.X = t2 .X, t.Z = t2 .Z (6)
Nguyễn Văn Diêu 3. Logical Design :: Multivalued Dependencies :: Theorem 195/248
Theorem (cont.)
r : R(XYZ):
1. Theorem 3.6 gives us a method to test if a relation r(R) satisfies X ↠ Y:
1. r1 = π XY (r), r2 = π XZ (r)
2. Test if r = r1 ⋊
⋉ r2 ?
2. Another method: Use only some sorting and counting.
1. Given X-value x:
2. n1 : tuples in r1 with X-value x
3. n2 : tuples in r2 with X-value x
4. n: tuples in r with X-value x
5. If n = n1 × n2 for any X-value x, then r = r1 ⋊
⋉ r2
Nguyễn Văn Diêu 3. Logical Design :: Multivalued Dependencies :: Test MVDs 197/248
Test MVDs (cont.)
Define the function counts the number of different W-values associated with a given
X-value in r.
Nguyễn Văn Diêu 3. Logical Design :: Multivalued Dependencies :: Test MVDs 198/248
e.g.
R(ABCD) , Test AB ↠ C
r (R: A B C D)
t1 : 1 1 1 1
t2 : 1 1 2 2
t3 : 1 1 1 2
t4 : 1 1 2 1
t5 : 1 2 2 1
t6 : 2 1 1 2
Nguyễn Văn Diêu 3. Logical Design :: Multivalued Dependencies :: Test MVDs 199/248
Inference Axioms MVDs Alone
r(R) ; W, X, Y, Z be subsets of R.
M3. Transitivity
M1. Reflexivity }
X↠Y
Y ⊆ X |= X ↠ Y |= X ↠ Z − Y
Y↠Z
M2. Augmentation
} M4. Additivity
X↠Y }
|= XZ ↠ YW X↠Y
W⊆Z |= X ↠ YZ
X↠Z
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: MVDs Alone 200/248
Inference Axioms MVDs Alone (cont.)
M5. Decomposition
}
X↠Y X↠Y∩Z
|= X↠Y−Z
X↠Z
X↠Z−Y
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: MVDs Alone 201/248
Inference Axioms FDs and MVDs
r(R) ; W, X, Y, Z be subsets of R.
C1. Replication
X → Y |= X ↠ Y
C2. Coalescence
X↠Y
∃W, W ∩ Y = ∅
|= X → Z
W→Z
Z⊆Y
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: FDs and MVD 202/248
e.g.
{ }
R(ABCDE) , D = A → BC, DE ↠ C
D |= A ↠ BDE ?
A → BC |= A ↠ BC (C1)
A ↠ BC |= A ↠ DE (M7)
}
A ↠ DE
|= A ↠ C (M3)
DE ↠ C
A ↠ C |= A ↠ BDE (M7) ■
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: FDs and MVD 203/248
Finding X+
F by Chase
R , F , X ⊆ R;
Compute X+ F all attributes that functionally depend on X.
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: Tableau Chase Test for MVDs 206/248
Tableau Chase Test for MVDs (cont.)
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: Projecting MVDs 209/248
Projecting MVDs (cont.)
Use A ↠ CD to swap the C and D components of these two rows to get two new rows:
R A B C D E
r1 (AC) 0 1 0 1 1
r2 (ABDE) 0 0 2 0 0
0 1 2 0 1
0 0 0 1 0
Notice: The last row has 0 in all the attributes of S, that is, A, B, and C. That is
enough to conclude that A ↠ C holds in S ■
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: Projecting MVDs 210/248
Minimum Dependency Basis
D ← XD
X++ ++
+ {Y′ } + {R − X′ Y′ }
2 ∀{Y1 , Y2 } ∈ X++
D : Y1 ∩ Y2 =
̸ ∅:
D ← XD
X++ − {Y1 , Y2 } + {Y1 ∩ Y2 } + {Y1 − Y2 } + {Y2 − Y1 }
++
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: Minimum Dependency Basis 211/248
Minimum Dependency Basis (cont.)
3 ∀W ↠ Z ∈ D : W ⊆ Y = Y1 Y2 . . . Yk , Yi ∈ X++
D
• D |= Y ↠ Z (augmentation)
{ }
• D |= X ↠ Z − Y (transitivity)
{ }
• If Z − Y is NOT the union of some sets in X++
D :
{ }
XD ← XD + Z − Y
++ ++
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: Minimum Dependency Basis 212/248
e.g.
{ }
R(ABCDE), D = A → BC, DE ↠ C
Find A++
D .
{ }
1. − Change to MVDs:
{ } D = A ↠ BC, DE ↠ C
− Initial A++
D = A
− A ↠ BC :{ }
A++D = A, BC, DE
2. None
3. DE ↠ C with
{ Y = DE : }
A++
D = A, BC, DE, C
2. Y1 = BC, Y{2 = C : }
A++
D = A, B, C, DE
3. None 2. None 3. None
{ }
Result: A++
D = A, B, C, DE
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: Minimum Dependency Basis 213/248
e.g.
{ }
R(ABCDE), D = A → BC, DE ↠ C
Find AD++
D .
{ }
1. − Change to MVDs: { D =
} A ↠ BC, DE ↠ C
− Initial AD++
D = A, D
− A ↠ BC : { }
AD++ D = A, D, BC, DE
2. Y1 = D, Y2 ={ DE : }
AD++
D = A, D, E, BC
3. DE ↠ C with{Y = DE : }
AD++
D = A, D, E, BC, C
2. Y1 = BC, Y2 {= C : }
AD++
D = A, D, E, B, C
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: Minimum Dependency Basis 214/248
e.g. (cont.)
3. None
2. None
3. None
{ }
Result: AD++
D = A, B, C, D, E
So that: D |= AD ↠ BE
We can test this MVD by use the Axioms or Tableau and Chase.
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: Minimum Dependency Basis 215/248
Another Algorithm
For each V ↠ W ∈ D
If ( ∃Y ∈ X++
D : Y ∩ W ̸= ∅ , Y ∩ V = ∅ ) then
D ← XD
X++ − {Y} + {Y ∩ W} + {Y − W}
++
3 X++
D is dependency basis of X
Nguyễn Văn Diêu 3. Logical Design :: Axioms for MVDs :: Beeri Algorithm 216/248
Fourth Normal Form
Definition
{ }
R , D = FDs, MVDs
R is in fourth normal form (4NF) if for every X ↠ Y :
• X ↠ Y is a trivial MVD or
• X is a superkey for R
e.g. { }
R(ABCDE) , D = A → BC, C ↠ DE .
R is not in 4NF because of the C ↠ DE.
R consisting of the two R1 (ABC) and R2 (CDE) is in 4NF with respect to D,
even though A ↠ B is implied by D and applies to R1 .
A ↠ B is not trivial, but A is a key for R1 .
Nguyễn Văn Diêu 3. Logical Design :: 4NF :: Decomposition into 4NF 219/248
Decomposition into 4NF (cont.)
For example, we have r(ABC) decomposes conserve information onto AB, AC and BC.
r (A B C)
1 1 1
1 2 2
3 3 3
4 3 4
5 5 5
6 6 5
r = π AB (r) ⋊
⋉ π AC (r) ⋊
⋉ π BC (r)
r = π R1 (r) ⋊
⋉ π R2 (r) ⋊
⋉ ··· ⋊
⋉ π Rp (r)
We also write ∗[R1 , R2 , · · · , Rp ] as ∗[R]
e.g.
In example 11.1, r satisfies the JD ∗[AB, AC, BC]
We know:
1. r(R) satisfies X ↠ Y ⇔ r decomposes conserve information onto XY and XZ,
where Z = R − (XY).
2. This condition is just JD ∗[XY, XZ].
3. JD ∗[R1 , R2 ] is the same as the R1 ∩ R2 ↠ R1 .
4. We can also define JDs in a manner similar to the definition of MVDs.
5. Let r satisfy ∗[R1 , R2 , · · · , Rp ]. If r contains tuples t1 , t2 , · · · , tp such that
ti (Ri ∩ Rj ) = tj (Ri ∩ Rj )
for all i, j,
r must contain t such that t(Ri ) = ti (Ri ), 1 ⩽ i ⩽ p.
Suppose relation r(ABCDE) satisfies the JD ∗[ABC, BD, CDE] and contains the three
tuples shown below.
r (A B C D E)
t1 1 1 1 1 1
t2 2 1 2 2 3
t3 3 2 1 2 2
Given R, X → Y holds on R.
If any S ⊇ R. Whether X → Y holds on S ?
This is evident for FDs because the definition of FDs did not concert to other XY set.
r (R: X Y) r (S: X Y Z W)
1 2 1 2 © §
1 2 1 2 x y
3 4 3 4 þ ÿ
3 4 3 4 Y §
Nguyễn Văn Diêu 3. Logical Design :: Embedded Functional Dependencies :: Definition 228/248
Embedded Multivalued Dependencies
Consider the relation r(ABCD). The projection π ABC (r) satisfies A ↠ B, but r itself
does not.
r (A B C) r (A B C D)
1 1 1 1 1 1 1
1 2 1 1 2 1 1
1 1 2 1 1 2 2
1 2 2 1 2 2 1
2 2 2 2 2 2 2
Definition: Relation r(R) satisfies the embedded multivalued dependency X ↠ Y|Z if
the X ↠ Y is satisfied by the π X∪Y∪Z (r).
Read: ’X multivalued determines Y in the context of Z’.
Nguyễn Văn Diêu 3. Logical Design :: Embedded Functional Dependencies :: Embedded MVDs 229/248
Embedded Join Dependencies
Nguyễn Văn Diêu 3. Logical Design :: Embedded Functional Dependencies :: Embedded JD 230/248
Overview
• A construction materials store wants to manage Product including names and unit
prices.
• List of ordering customers or potential customers with customer name and
address information.
• Every time an order is placed by a customer, the order needs to store the order
date, pick-up date, and customer. Order along with a list of products ordered and
quantity ordered.
• When delivery is due, issue a delivery invoice knowing that each order can be
delivered in multiple deliveries with different delivery quantities and each Order
there is an invoice for billing.
• The unit price at delivery may be different from the reference price in stock at the
time of ordering.
Nguyễn Văn Diêu 4. Physical Design :: Conceptual to Physical :: Relational Model 235/248
Functional Dependencies
Nguyễn Văn Diêu 4. Physical Design :: Conceptual to Physical :: Relational Model 236/248
Normal Form
Nguyễn Văn Diêu 4. Physical Design :: Conceptual to Physical :: Normal Form 237/248
Normalization
Normalization for:
• Invoice Detail(Invoice ID, Order ID, Product ID, Invoice Unit Price,
Invoice Quantity) 1NF
Result:
• R1 (Invoice ID, Order ID) BCNF
• R2 (Invoice ID, Product ID, Invoice Unit Price, Invoice Quantity) BCNF
Nguyễn Văn Diêu 4. Physical Design :: Conceptual to Physical :: Customize Name 240/248
Foreign Keys
Nguyễn Văn Diêu 4. Physical Design :: Conceptual to Physical :: Foreign Keys 241/248
SQL Script
Using indexes:
• To optimize data access
Accessing to data is faster with an index than without an index.
• To ensure uniqueness
A table with a unique index cannot have two rows with the same values in the
column or columns that form the index key.
• To enable clustering
When indexing, similar values will partition, optimizing page access for data.