CH 7
CH 7
Database System Concepts - 7th Edition 7.2 ©Silberschatz, Korth and Sudarshan
Overview of Normalization
Database System Concepts - 7th Edition 7.3 ©Silberschatz, Korth and Sudarshan
Features of Good Relational Designs
Database System Concepts - 7th Edition 7.4 ©Silberschatz, Korth and Sudarshan
Decomposition
The problem arises when we have two employees with the same name
▪ The next slide shows how we lose information -- we cannot reconstruct
the original employee relation -- and so, this is a lossy decomposition.
Database System Concepts - 7th Edition 7.5 ©Silberschatz, Korth and Sudarshan
A Lossy Decomposition
Database System Concepts - 7th Edition 7.6 ©Silberschatz, Korth and Sudarshan
Lossless Decomposition
Database System Concepts - 7th Edition 7.7 ©Silberschatz, Korth and Sudarshan
Example of Lossless Decomposition
▪ Decomposition of R = (A, B, C)
R1 = (A, B) R2 = (B, C)
Database System Concepts - 7th Edition 7.8 ©Silberschatz, Korth and Sudarshan
Normalization Theory
Database System Concepts - 7th Edition 7.9 ©Silberschatz, Korth and Sudarshan
Functional Dependencies
▪ There are usually a variety of constraints (rules) on the data in the real
world.
▪ For example, some of the constraints that are expected to hold in a
university database are:
• Students and instructors are uniquely identified by their ID.
• Each student and instructor has only one name.
• Each instructor and student is (primarily) associated with only one
department.
• Each department has only one value for its budget, and only one
associated building.
Database System Concepts - 7th Edition 7.10 ©Silberschatz, Korth and Sudarshan
Functional Dependencies (Cont.)
Database System Concepts - 7th Edition 7.11 ©Silberschatz, Korth and Sudarshan
Functional Dependencies Definition
▪ Let R be a relation schema
R and R
▪ The functional dependency
→
holds on R if and only if for any legal relations r(R), whenever any two
tuples t1 and t2 of r agree on the attributes , they also agree on the
attributes . That is,
1 4
1 5
3 7
Database System Concepts - 7th Edition 7.12 ©Silberschatz, Korth and Sudarshan
Closure of a Set of Functional Dependencies
Database System Concepts - 7th Edition 7.13 ©Silberschatz, Korth and Sudarshan
Keys and Functional Dependencies
Database System Concepts - 7th Edition 7.14 ©Silberschatz, Korth and Sudarshan
Use of Functional Dependencies
Database System Concepts - 7th Edition 7.15 ©Silberschatz, Korth and Sudarshan
Trivial Functional Dependencies
Database System Concepts - 7th Edition 7.16 ©Silberschatz, Korth and Sudarshan
Lossless Decomposition
Database System Concepts - 7th Edition 7.17 ©Silberschatz, Korth and Sudarshan
Example
▪ R = (A, B, C)
F = {A → B, B → C)
▪ R1 = (A, B), R2 = (B, C)
• Lossless decomposition:
R1 R2 = {B} and B → BC
▪ R1 = (A, B), R2 = (A, C)
• Lossless decomposition:
R1 R2 = {A} and A → AB
▪ Note:
• B → BC
is a shorthand notation for
• B → {B, C}
Database System Concepts - 7th Edition 7.18 ©Silberschatz, Korth and Sudarshan
Dependency Preservation
Database System Concepts - 7th Edition 7.19 ©Silberschatz, Korth and Sudarshan
Dependency Preservation Example
▪ Consider a schema:
dept_advisor(s_ID, i_ID, department_name)
▪ With function dependencies:
i_ID → dept_name
s_ID, dept_name → i_ID
▪ In the above design we are forced to repeat the department name once
for each time an instructor participates in a dept_advisor relationship.
▪ To fix this, we need to decompose dept_advisor
▪ Any decomposition will not include all the attributes in
s_ID, dept_name → i_ID
▪ Thus, the composition NOT be dependency preserving
Database System Concepts - 7th Edition 7.20 ©Silberschatz, Korth and Sudarshan
Normal Forms
Database System Concepts - 7th Edition 7.21 ©Silberschatz, Korth and Sudarshan
Boyce-Codd Normal Form
Database System Concepts - 7th Edition 7.22 ©Silberschatz, Korth and Sudarshan
Boyce-Codd Normal Form (Cont.)
Database System Concepts - 7th Edition 7.23 ©Silberschatz, Korth and Sudarshan
Decomposing a Schema into BCNF
Database System Concepts - 7th Edition 7.24 ©Silberschatz, Korth and Sudarshan
Example
▪ R = (A, B, C)
F = {A → B, B → C)
▪ R1 = (A, B), R2 = (B, C)
• Lossless-join decomposition:
R1 R2 = {B} and B → BC
• Dependency preserving
▪ R1 = (A, B), R2 = (A, C)
• Lossless-join decomposition:
R1 R2 = {A} and A → AB
• Not dependency preserving
Database System Concepts - 7th Edition 7.25 ©Silberschatz, Korth and Sudarshan
BCNF and Dependency Preservation
Database System Concepts - 7th Edition 7.26 ©Silberschatz, Korth and Sudarshan
Third Normal Form
Database System Concepts - 7th Edition 7.27 ©Silberschatz, Korth and Sudarshan
3NF Example
▪ Consider a schema:
dept_advisor(s_ID, i_ID, dept_name)
▪ With function dependencies:
i_ID → dept_name
s_ID, dept_name → i_ID
▪ Two candidate keys = {s_ID, dept_name}, {s_ID, i_ID }
▪ We have seen before that dept_advisor is not in BCNF
▪ R, however, is in 3NF
• s_ID, dept_name is a candidate key
• i_ID → dept_name and i_ID is NOT a superkey, but:
▪ { dept_name} – {i_ID } = {dept_name } and
▪ dept_name is contained in a candidate key
Database System Concepts - 7th Edition 7.28 ©Silberschatz, Korth and Sudarshan
Redundancy in 3NF
Database System Concepts - 7th Edition 7.29 ©Silberschatz, Korth and Sudarshan
Comparison of BCNF and 3NF
Database System Concepts - 7th Edition 7.30 ©Silberschatz, Korth and Sudarshan
Goals of Normalization
Database System Concepts - 7th Edition 7.31 ©Silberschatz, Korth and Sudarshan
How good is BCNF?
Database System Concepts - 7th Edition 7.32 ©Silberschatz, Korth and Sudarshan
How good is BCNF? (Cont.)
Database System Concepts - 7th Edition 7.33 ©Silberschatz, Korth and Sudarshan
Higher Normal Forms
• inst_phone:
▪ This suggests the need for higher normal forms, such as Fourth
Normal Form (4NF), which we shall see later
Database System Concepts - 7th Edition 7.34 ©Silberschatz, Korth and Sudarshan
Functional-Dependency Theory
Database System Concepts - 7th Edition 7.35 ©Silberschatz, Korth and Sudarshan
Functional-Dependency Theory Roadmap
Database System Concepts - 7th Edition 7.36 ©Silberschatz, Korth and Sudarshan
Closure of a Set of Functional Dependencies
Database System Concepts - 7th Edition 7.37 ©Silberschatz, Korth and Sudarshan
Closure of a Set of Functional Dependencies
Database System Concepts - 7th Edition 7.38 ©Silberschatz, Korth and Sudarshan
Example of F+
▪ R = (A, B, C, G, H, I)
F={A→B
A→C
CG → H
CG → I
B → H}
▪ Some members of F+
• A→H
▪ by transitivity from A → B and B → H
• AG → I
▪ by augmenting A → C with G, to get AG → CG
and then transitivity with CG → I
• CG → HI
▪ by augmenting CG → I to infer CG → CGI,
and augmenting of CG → H to infer CGI → HI,
and then transitivity
Database System Concepts - 7th Edition 7.39 ©Silberschatz, Korth and Sudarshan
Closure of Functional Dependencies (Cont.)
▪ Additional rules:
• Union rule: If → holds and → holds, then → holds.
• Decomposition rule: If → holds, then → holds and →
holds.
• Pseudotransitivity rule:If → holds and → holds, then
→ holds.
▪ The above rules can be inferred from Armstrong’s axioms.
Database System Concepts - 7th Edition 7.40 ©Silberschatz, Korth and Sudarshan
Closure of Attribute Sets
Database System Concepts - 7th Edition 7.42 ©Silberschatz, Korth and Sudarshan
Example of Attribute Set Closure
▪ R = (A, B, C, G, H, I)
▪ F = {A → B
A→C
CG → H
CG → I
B → H}
▪ (AG)+
1. result = AG
2. result = ABCG (A → C and A → B)
3. result = ABCGH (CG → H and CG AGBC)
4. result = ABCGHI (CG → I and CG AGBCH)
▪ Is AG a candidate key?
1. Is AG a super key?
1. Does AG → R? == Is R (AG)+
2. Is any subset of AG a superkey?
1. Does A → R? == Is R (A)+
2. Does G → R? == Is R (G)+
3. In general: check for each subset of size n-1
Database System Concepts - 7th Edition 7.43 ©Silberschatz, Korth and Sudarshan
Uses of Attribute Closure
Database System Concepts - 7th Edition 7.44 ©Silberschatz, Korth and Sudarshan
Canonical Cover
Database System Concepts - 7th Edition 7.45 ©Silberschatz, Korth and Sudarshan
Extraneous Attributes
Database System Concepts - 7th Edition 7.46 ©Silberschatz, Korth and Sudarshan
Extraneous Attributes (Cont.)
Database System Concepts - 7th Edition 7.47 ©Silberschatz, Korth and Sudarshan
Extraneous Attributes
Database System Concepts - 7th Edition 7.48 ©Silberschatz, Korth and Sudarshan
Examples of Extraneous Attributes
Database System Concepts - 7th Edition 7.50 ©Silberschatz, Korth and Sudarshan
Canonical Cover
Database System Concepts - 7th Edition 7.51 ©Silberschatz, Korth and Sudarshan
Example: Computing a Canonical Cover
▪ R = (A, B, C)
F = {A → BC
B→C
A→B
AB → C}
▪ Combine A → BC and A → B into A → BC
• Set is now {A → BC, B → C, AB → C}
▪ A is extraneous in AB → C
• Check if the result of deleting A from AB → C is implied by the other
dependencies
▪ Yes: in fact, B → C is already present!
• Set is now {A → BC, B → C}
▪ C is extraneous in A → BC
• Check if A → C is logically implied by A → B and the other dependencies
▪ Yes: using transitivity on A → B and B → C.
• Can use attribute closure of A in more complex cases
▪ The canonical cover is: A→B
B→C
Database System Concepts - 7th Edition 7.53 ©Silberschatz, Korth and Sudarshan
Dependency Preservation
Database System Concepts - 7th Edition 7.54 ©Silberschatz, Korth and Sudarshan
Example
▪ R = (A, B, C )
F = {A → B
B → C}
Key = {A}
▪ R is not in BCNF
▪ Decomposition R1 = (A, B), R2 = (B, C)
• R1 and R2 in BCNF
• Lossless-join decomposition
• Dependency preserving
Database System Concepts - 7th Edition 7.57 ©Silberschatz, Korth and Sudarshan
Example of BCNF Decomposition
Database System Concepts - 7th Edition 7.62 ©Silberschatz, Korth and Sudarshan
BCNF Decomposition (Cont.)
▪ course is in BCNF
• How do we know this?
▪ building, room_number→capacity holds on class-1
• but {building, room_number} is not a superkey for class-1.
• We replace class-1 by:
▪ classroom (building, room_number, capacity)
▪ section (course_id, sec_id, semester, year, building,
room_number, time_slot_id)
▪ classroom and section are in BCNF.
Database System Concepts - 7th Edition 7.63 ©Silberschatz, Korth and Sudarshan
Third Normal Form
Database System Concepts - 7th Edition 7.64 ©Silberschatz, Korth and Sudarshan
3NF Example -- Relation dept_advisor
Database System Concepts - 7th Edition 7.65 ©Silberschatz, Korth and Sudarshan
3NF Decomposition: An Example
▪ Relation schema:
cust_banker_branch = (customer_id, employee_id, branch_name, type )
▪ The functional dependencies for this relation schema are:
• customer_id, employee_id → branch_name, type
• employee_id → branch_name
• customer_id, branch_name → employee_id
▪ We first compute a canonical cover
• branch_name is extraneous in the r.h.s. of the 1st dependency
• No other attribute is extraneous, so we get FC =
customer_id, employee_id → type
employee_id → branch_name
customer_id, branch_name → employee_id
Database System Concepts - 7th Edition 7.69 ©Silberschatz, Korth and Sudarshan
3NF Decompsition Example (Cont.)
Database System Concepts - 7th Edition 7.70 ©Silberschatz, Korth and Sudarshan
Comparison of BCNF and 3NF
Database System Concepts - 7th Edition 7.71 ©Silberschatz, Korth and Sudarshan
Design Goals
Database System Concepts - 7th Edition 7.72 ©Silberschatz, Korth and Sudarshan
Multivalued Dependencies
Database System Concepts - 7th Edition 7.73 ©Silberschatz, Korth and Sudarshan
Multivalued Dependencies (MVDs)
Database System Concepts - 7th Edition 7.74 ©Silberschatz, Korth and Sudarshan
Multivalued Dependencies
Database System Concepts - 7th Edition 7.75 ©Silberschatz, Korth and Sudarshan
MVD (Cont.)
▪ Let R be a relation schema with a set of attributes that are partitioned into
3 nonempty subsets.
Y, Z, W
▪ We say that Y →→ Z (Y multidetermines Z )
if and only if for all possible relations r (R )
< y1, z1, w1 > r and < y1, z2, w2 > r
then
< y1, z1, w2 > r and < y1, z2, w1 > r
▪ Note that since the behavior of Z and W are identical it follows that
Y →→ Z if Y →→ W
Database System Concepts - 7th Edition 7.77 ©Silberschatz, Korth and Sudarshan
Example
▪ In our example:
ID →→ child_name
ID →→ phone_number
▪ The above formal definition is supposed to formalize the notion that given
a particular value of Y (ID) it has associated with it a set of values of Z
(child_name) and a set of values of W (phone_number), and these two
sets are in some sense independent of each other.
▪ Note:
• If Y → Z then Y →→ Z
• Indeed we have (in above notation) Z1 = Z2
The claim follows.
Database System Concepts - 7th Edition 7.78 ©Silberschatz, Korth and Sudarshan
Use of Multivalued Dependencies
Database System Concepts - 7th Edition 7.79 ©Silberschatz, Korth and Sudarshan
Theory of MVDs
Database System Concepts - 7th Edition 7.80 ©Silberschatz, Korth and Sudarshan
Fourth Normal Form
Database System Concepts - 7th Edition 7.81 ©Silberschatz, Korth and Sudarshan
Example
▪ R =(A, B, C, G, H, I)
F ={ A →→ B
B →→ HI
CG →→ H }
▪ R is not in 4NF since A →→ B and A is not a superkey for R
▪ Decomposition
a) R1 = (A, B) (R1 is in 4NF)
b) R2 = (A, C, G, H, I) (R2 is not in 4NF, decompose into R3 and R4)
c) R3 = (C, G, H) (R3 is in 4NF)
d) R4 = (A, C, G, I) (R4 is not in 4NF, decompose into R5 and R6)
• A →→ B and B →→ HI ➔ A →→ HI, (MVD transitivity), and
• and hence A →→ I (MVD restriction to R4)
e) R5 = (A, I) (R5 is in 4NF)
f)R6 = (A, C, G) (R6 is in 4NF)
Database System Concepts - 7th Edition 7.84 ©Silberschatz, Korth and Sudarshan
Modeling Temporal Data
▪ Temporal data have an association time interval during which the data
are valid.
▪ A snapshot is the value of the data at a particular point in time
▪ Several proposals to extend ER model by adding valid time to
• attributes, e.g., address of an instructor at different points in time
• entities, e.g., time duration when a student entity exists
• relationships, e.g., time during which an instructor was associated with
a student as an advisor.
▪ But no accepted standard
▪ Adding a temporal component results in functional dependencies like
ID → street, city
not holding, because the address varies over time
▪ A temporal functional dependency X → Y holds on schema R if the
functional dependency X → Y holds on all snapshots for all legal instances
r (R).
Database System Concepts - 7th Edition 7.91 ©Silberschatz, Korth and Sudarshan
Modeling Temporal Data (Cont.)
▪ In practice, database designers may add start and end time attributes to
relations
• E.g., course(course_id, course_title) is replaced by
course(course_id, course_title, start, end)
• Constraint: no two tuples can have overlapping valid times
▪ Hard to enforce efficiently
▪ Foreign key references may be to current version of data, or to data at a
point in time
• E.g., student transcript should refer to course information at the time
the course was taken
Database System Concepts - 7th Edition 7.92 ©Silberschatz, Korth and Sudarshan
End of Chapter 7
Database System Concepts - 7th Edition 7.93 ©Silberschatz, Korth and Sudarshan