0% found this document useful (0 votes)
8 views37 pages

Chapter 7

Chapter 7 of 'Database System Concepts' discusses relational database design, focusing on the importance of first normal form (1NF) and the concept of functional dependencies. It outlines the criteria for determining if a relation is in good form and the process for decomposing relations that are not, emphasizing the significance of atomic domains and the implications of functional dependencies. The chapter also introduces higher normal forms, including second normal form (2NF), Boyce-Codd normal form (BCNF), and third normal form (3NF), detailing their definitions and the rationale behind normalization.

Uploaded by

aryabloom74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views37 pages

Chapter 7

Chapter 7 of 'Database System Concepts' discusses relational database design, focusing on the importance of first normal form (1NF) and the concept of functional dependencies. It outlines the criteria for determining if a relation is in good form and the process for decomposing relations that are not, emphasizing the significance of atomic domains and the implications of functional dependencies. The chapter also introduces higher normal forms, including second normal form (2NF), Boyce-Codd normal form (BCNF), and third normal form (3NF), detailing their definitions and the rationale behind normalization.

Uploaded by

aryabloom74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Database System Concept

by Silberschatz, Korth and Sudarshan

Chapter 7 : Relational Database Design


First Normal Form
• Domain is atomic if its elements are considered to be indivisible
units
• Examples of non-atomic domains:
• Set of names, composite attributes
• Identification numbers like CSE1101 that can be broken up into parts

• A relational schema R is in first normal form if the domains of all


attributes of R are atomic
• Non-atomic values complicate storage and encourage redundant
(repeated) storage of data

2
First Normal Form (Cont’d)

• Atomicity is actually a property of how the elements of the


domain are used.

• Suppose that students are given roll numbers which are


strings of the form CS0012 or EE1127, If the first two
characters are extracted to find the department, the
domain of roll numbers is not atomic.

3
Goal — Devise a Theory for the Following
• Decide whether a particular relation R is in “good” form.

• In the case that a relation R is not in “good” form, decompose it into a set of
relations {R1, R2, ..., Rn} such that
• each relation is in good form
• the decomposition is a lossless-join decomposition

• Theory is based on:


• functional dependencies
• multivalued dependencies
4
Functional Dependencies

• Constraints on the set of legal relations.

• Require that the value for a certain set of attributes determines uniquely
the value for another set of attributes.

• A functional dependency is a generalization of the notion of a key.

5
Functional Dependencies (Cont.)
• 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,
t1[α] = t2 [α] ⇒ t1[β ] = t2 [β ]

For a super key K, if t1[K] = t2 [K] it indicates t1[R ] = t2 [R ] (i.e t1=t2)

A functional dependency is a generalization of the notion of a super key.


6
Functional Dependencies (Cont.)
• Example: Consider r(A,B ) with the following
instance of r.
1 4
1 5
3 7

• On this instance, A → B does NOT hold, but B


→ A does hold.

7
Functional Dependencies (Cont.)

A->C ?? Find all the FDs!!! F+


How about C->A ???
AB->D ?? Home task 8
Functional Dependencies (Cont.)
• K is a super key for relation schema R if and only if K → R
• K is a candidate key for R if and only if
• K → R, and
• For no α ⊂ K, α → R

• Functional dependencies allow us to express constraints that cannot be expressed


using super keys. Consider the schema:
bor_loan = (customer_id, loan_number, amount ).

We expect this functional dependency to hold:


loan_number → amount
but would not expect the following to hold:
amount → customer_name
9
Use of Functional Dependencies
• We use functional dependencies to:
• test relations to see if they are legal under a given set of
functional dependencies.
• If a relation r is legal under a set F of functional dependencies,
we say that r satisfies F.

• specify constraints on the set of legal relations


• We say that F holds on R if all legal relations on R satisfy the set
of functional dependencies F.

10
Functional Dependencies (Cont.)
• A functional dependency is trivial if it is satisfied by all
instances of a relation

• Example:
• customer_name, loan_number → customer_name
• customer_name → customer_name

• In general, α → β is trivial if β ⊆ α

11
Closure of a Set of Functional Dependencies
• Given a set F of functional dependencies, there are other
functional dependencies that are logically implied by F.
• For example: If A → B and B → C, then we can derive
that A → C

• The set of all functional dependencies logically implied by F is


the closure of F.
• We denote the closure of F by F+.
• F+ is a superset of F.
12
Closure of a Set of Functional Dependencies

• We can find all of F+ by applying Armstrong’s Axioms:


• if β ⊆ α, then α → β (reflexivity)
• if α → β, then γ α → γ β (augmentation)
• if α → β, and β → γ, then α → γ (transitivity)

• These rules are


• sound (generate only functional dependencies that actually
hold) and
• complete (generate all functional dependencies that hold).
13
Example
⚫ 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,
14
and then transitivity
Procedure for Computing F+
• To compute the closure of a set of functional dependencies F:

F+=F
repeat
for each functional dependency f in F+
apply reflexivity and augmentation rules on f
add the resulting functional dependencies to F +
for each pair of functional dependencies f1and f2 in F +
if f1 and f2 can be combined using transitivity
then add the resulting functional dependency to F +
until F + does not change any further

15
Closure of Functional Dependencies (Cont.)

• We can further simplify manual computation of F+ by


using the following additional rules.
• If α → β holds and α → γ holds, then α → β γ holds (union)
• If α → β γ holds, then α → β holds and α → γ holds
(decomposition)
• If α → β holds and γ β → δ holds, then α γ → δ holds
(pseudotransitivity)
The above rules can be inferred from Armstrong’s axioms.

16
Closure of Attribute Sets
⚫ Given a set of attributes α, define the closure of α under F
(denoted by α+) as the set of attributes that are functionally
determined by α under F

⚫ Algorithm to compute α+, the closure of α under F

result := α;
while (changes to result) do
for each β → γ in F do
begin
if β ⊆ result then result := result ∪ γ
end
17
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)
18
Uses of Attribute Closure
There are several uses of the attribute closure algorithm:
• Testing for superkey:
• To test if α is a superkey, we compute α+, and check if α+ contains all attributes
of R.
• Testing functional dependencies
• To check if a functional dependency α → β holds (or, in other words, is in F+),
just check if β ⊆ α+.
• That is, we compute α+ by using attribute closure, and then check if it contains
β.
• Is a simple and cheap test, and very useful
• Computing closure of F
• For each γ ⊆ R, we find the closure γ+, and for each S ⊆ γ+, we output a
functional dependency γ → S.
19
Goals of Normalization
• Let R be a relation scheme with a set F of functional dependencies.
• Decide whether a relation scheme R is in “good” form.
• In the case that a relation scheme R is not in “good” form, decompose
it into a set of relation scheme {R1, R2, ..., Rn} such that
• each relation scheme is in good form
• the decomposition is a lossless-join decomposition
• Preferably, the decomposition should be dependency preserving.

20
Second Normal Form (2NF)
• A table is in 2NF if it is in 1NF and each non-key field is functionally
dependent on the entire primary key.

• Functional dependency: a relationship between fields such that the value in


one field determines the one value that can be contained in the other field.

• Determinant: a field in which the value determines the value in another


field.

Example
Airport – City
Dulles – Washington, DC
21
Second Normal Form (2NF)
A table is in 2NF if it is in 1NF and each non-key field is functionally
dependent on the entire primary key.
Employees_Projects Violates 2NF
*EmpID Lname Fname *ProjNum ProjTitle
EN1-25 O’Brien Sean 30-452-T3 STAR Manual
EN1-25 O’Brien Sean 30-457-T3 ISO
Procedures
EN1-25 O’Brien Sean 31-124-T3 Employee
Handbook
EN1-33 Guya Amy 30-452-T3 STAR Manual
EN1-33 Guya Amy 30-482-TC Web site 22
Tables in 2NF
Employees
*EmployeeID LastName FirstName
EN1-26 O’Brien Sean
EN1-33 Guya Amy

Employees_Projects Projects
*EmployeeID *ProjNum *ProjNu Title
EN1-26 30-452-T3 m
30-452-T3 STAR manual
EN1-33 30-457-T3
30-457-T3 ISO procedure
23
Boyce-Codd Normal Form
A relation schema R is in BCNF with respect to a set F of functional
dependencies if for all functional dependencies in F+ of the form
α→ β
where α ⊆ R and β ⊆ R, at least one of the following holds:

• α → β is trivial (i.e., β ⊆ α)
• α is a super key for R

Example schema not in BCNF:


bor_loan = ( customer_id, loan_number, amount )
because loan_number → amount holds but loan_number is not a super key

24
Decomposing a Schema into BCNF
• Suppose we have a schema R and a non-trivial dependency
α→β causes a violation of BCNF.
We decompose R into:

•(αU β )
•( R - ( β - α ) )
• In our example,
• α = loan_number
• β = amount
and bor_loan is replaced by
• (αU β ) = ( loan_number, amount ) 25

• ( R - ( β - α ) ) = ( customer_id, loan_number )
Sample BCNF Violation
Course_Students_TAs

CourseNum Student TA
ENG101 Jones Clark
ENG101 Grayson Chen
ENG101 Samara Chen
MAT350 Grayson Powers
MAT350 Jones O’Shea
MAT350 Berg Powers
26
Tables in BCNF
Courses
*CourseNum *Student
ENG101 Jones
MAT350 Grayson
Students TAs
*Student *TA *CourseNum *TA
Jones Clark ENG101 Clark
Grayson Chen MAT350 Chen
27
Canonical Cover
• Set of functional dependencies may have redundant dependencies that can
be inferred from the others
• For example: A → C is redundant in: {A → B, B → C}
• Parts of a functional dependency may be redundant
• E.g.: on RHS: {A → B, B → C, A → CD} can be simplified to
{A → B, B → C, A → D}
• E.g.: on LHS: {A → B, B → C, AC → D} can be simplified to
{A → B, B → C, A → D}

• Intuitively, a canonical cover of F is a “minimal” set of functional


dependencies equivalent to F, having no redundant dependencies or
redundant parts of dependencies

28
Canonical Cover

• A canonical cover for F is a set of dependencies Fc such that


• F logically implies all dependencies in Fc, and
• Fc logically implies all dependencies in F, and
• No functional dependency in Fc contains an extraneous
attribute, and
• Each left side of functional dependency in Fc is unique.

Every FD in the canonical cover is needed, otherwise some dependencies are


lost
29
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
30
Example of BCNF Decomposition
• R = (A, B, C )
F = {A → B
B → C}
Key = {A}
• R is not in BCNF (B → C but B is not superkey)
• Decomposition
• R1 = (B, C)
• R2 = (A,B)

31
Third Normal Form: Motivation

• Because it is not always possible to achieve both BCNF and


dependency preservation, we consider a weaker normal form,
known as third normal form.

• There are some situations where


• BCNF is not dependency preserving, and
• Efficient checking for FD violation on updates is important

32
Third Normal Form
• Solution: define a weaker normal form, called Third
Normal Form (3NF)
• Allows some redundancy
• But functional dependencies can be checked on individual
relations without computing a join.
• There is always a lossless-join, dependency-preserving
decomposition into 3NF.

33
Third Normal Form
• A relation schema R is in third normal form (3NF) if for all:
α → β in F+
at least one of the following holds:
• α → β is trivial (i.e., β ∈ α)
• α is a super key for R
• Each attribute A in β – α is contained in a candidate key for R.
(NOTE: each attribute may be in a different candidate key)
• If a relation is in BCNF it is in 3NF (since in BCNF one of the first two
conditions above must hold).
• Third condition is a minimal relaxation of BCNF to ensure dependency
preservation .
34
3NF Example

• Relation R:
• R = (J, K, L )
F = {JK → L, L → K }
• Two candidate keys: JK and JL
• R is in 3NF
JK → L JK is a superkey
L → K K is contained in a candidate key

35
Comparison of BCNF and 3NF

• It is always possible to decompose a relation into a set of


relations that are in 3NF such that:
• the decomposition is lossless
• the dependencies are preserved
• It is always possible to decompose a relation into a set of
relations that are in BCNF such that:
• the decomposition is lossless
• it may not be possible to preserve dependencies.

36
Thank You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy