Docsity

Database Normalization: Concepts and Techniques, Slides of Database Management Systems (DBMS)

Toggle sidebar
bg1
1
Computing & Information Sciences
Kansas State University
Friday, 29 Sep 2006CIS 560: Database System Concepts
Lecture 16 of 42
Friday, 29 September 2006
William H. Hsu
Department of Computing and Information Sciences, KSU
KSOL course page: http://snipurl.com/va60
Course web site: http://www.kddresearch.org/Courses/Fall-2006/CIS560
Instructor home page: http://www.cis.ksu.edu/~bhsu
Reading for Next Class:
First half of Chapter 7, Silberschatz et al., 5th edition
Database Normalization
Notes: Rationale for Normalization
Computing & Information Sciences
Kansas State University
Friday, 29 Sep 2006CIS 560: Database System Concepts
Chapter 7: Relational Database Design
Chapter 7: Relational Database Design
zFeatures of Good Relational Design
zAtomic Domains and First Normal Form
zDecomposition Using Functional Dependencies
zFunctional Dependency Theory
zAlgorithms for Functional Dependencies
zDecomposition Using Multivalued Dependencies
zMore Normal Form
zDatabase-Design Process
zModeling Temporal Data
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Database Normalization: Concepts and Techniques and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Lecture 16 of 42

Friday, 29 September 2006

William H. Hsu Department of Computing and Information Sciences, KSU

KSOL course page: http://snipurl.com/va Course web site: http://www.kddresearch.org/Courses/Fall-2006/CIS Instructor home page: http://www.cis.ksu.edu/~bhsu

Reading for Next Class: First half of Chapter 7, Silberschatz et al. , 5 th^ edition

Database Normalization

Notes: Rationale for Normalization

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Chapter 7: Relational Database DesignChapter 7: Relational Database Design

z Features of Good Relational Design z Atomic Domains and First Normal Form z Decomposition Using Functional Dependencies z Functional Dependency Theory z Algorithms for Functional Dependencies z Decomposition Using Multivalued Dependencies z More Normal Form z Database-Design Process z Modeling Temporal Data

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Combine Schemas? Combine Schemas?

z Suppose we combine borrow and loan to get bor_loan = ( customer_id , loan_number , amount ) z Result is possible repetition of information (L-100 in example below)

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

A Combined Schema Without RepetitionA Combined Schema Without Repetition

z Consider combining loan_branch and loan loan_amt_br = ( loan_number , amount , branch_name ) z No repetition (as suggested by example below)

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

First Normal Form First Normal Form

z 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 CS101 that can be broken up into parts z A relational schema R is in first normal form if the domains of all attributes of R are atomic z Non-atomic values complicate storage and encourage redundant (repeated) storage of data ’ Example: Set of accounts stored with each customer, and set of owners stored with each account ’ We assume all relations are in first normal form (and revisit this in Chapter 9)

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

First Normal Form (Cont’d)First Normal Form (Cont’d)

z Atomicity is actually a property of how the elements of the domain are used. ’ Example: Strings would normally be considered indivisible ’ Suppose that students are given roll numbers which are strings of the form CS0012 or EE ’ If the first two characters are extracted to find the department, the domain of roll numbers is not atomic. ’ Doing so is a bad idea: leads to encoding of information in application program rather than in the database.

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Goal — Devise a Theory for the FollowingGoal — Devise a Theory for the Following

z Decide whether a particular relation R is in “good” form. z In the case that a relation R is not in “good” form, decompose it into a set of relations { R 1 , R 2 , ..., R (^) n } such that ’ each relation is in good form ’ the decomposition is a lossless-join decomposition z Our theory is based on: ’ functional dependencies ’ multivalued dependencies

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Functional Dependencies Functional Dependencies

z Constraints on the set of legal relations. z Require that the value for a certain set of attributes determines uniquely the value for another set of attributes. z A functional dependency is a generalization of the notion of a key.

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Use of Functional DependenciesUse of Functional Dependencies

z 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. z Note: A specific instance of a relation schema may satisfy a functional dependency even if the functional dependency does not hold on all legal instances. ’ For example, a specific instance of loan may, by chance, satisfy amount → customer_name.

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Functional Dependencies (Cont.)Functional Dependencies (Cont.)

z 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 β ⊆ α

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Closure of a Set of Functional DependenciesClosure of a Set of Functional Dependencies

z Given a set F set of functional dependencies, there are certain other functional dependencies that are logically implied by F. ’ For example: If A → B and B → C , then we can infer that A → C z The set of all functional dependencies logically implied by F is the closure of F. z We denote the closure of F by F +. z F+^ is a superset of F.

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Boyce-Codd Normal Form Boyce-Codd Normal Form

z α →β is trivial (i.e., β ⊆ α)

z α is a superkey for R

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:

Example schema not in BCNF:

bor_loan = ( customer_id, loan_number, amount )

because loan_number → amount holds on bor_loan but loan_number is not a superkey

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Third Normal Form Third Normal Form

z 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 superkey for R ’ Each attribute A in β – α is contained in a candidate key for R. ( NOTE : each attribute may be in a different candidate key) z If a relation is in BCNF it is in 3NF (since in BCNF one of the first two conditions above must hold). z Third condition is a minimal relaxation of BCNF to ensure dependency preservation (will see why later).

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Goals of NormalizationGoals of Normalization

z Let R be a relation scheme with a set F of functional dependencies. z Decide whether a relation scheme R is in “good” form. z In the case that a relation scheme R is not in “good” form, decompose it into a set of relation scheme { R 1 , R 2 , ..., R (^) n } such that ’ each relation scheme is in good form ’ the decomposition is a lossless-join decomposition ’ Preferably, the decomposition should be dependency preserving.

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

How good is BCNF? How good is BCNF?

z There are database schemas in BCNF that do not seem to be sufficiently normalized z Consider a database classes ( course, teacher, book )

such that ( c, t, b ) ∈ classes means that t is qualified to teach c, and b is a required textbook for c z The database is supposed to list for each course the set of teachers any one of which can be the course’s instructor, and the set of books, all of which are required for the course (no matter who teaches it).

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

z There are no non-trivial functional dependencies and therefore the relation is in BCNF z Insertion anomalies – i.e., if Marilyn is a new teacher that can teach database, two tuples need to be inserted (database, Marilyn, DB Concepts) (database, Marilyn, Ullman)

course teacher book database database database database database database operating systems operating systems operating systems operating systems

Avi Avi Hank Hank Sudarshan Sudarshan Avi Avi Pete Pete

DB Concepts Ullman DB Concepts Ullman DB Concepts Ullman OS Concepts Stallings OS Concepts Stallings classes

How good is BCNF? (Cont.) How good is BCNF? (Cont.)

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Closure of a Set of Functional DependenciesClosure of a Set of Functional Dependencies

z Given a set F set of functional dependencies, there are certain other functional dependencies that are logically implied by F. ’ For example: If A → B and B → C , then we can infer that A → C z The set of all functional dependencies logically implied by F is the closure of F. z We denote the closure of F by F+. z We can find all of F +^ by applying Armstrong’s Axioms: ’ if β ⊆ α, then α →β (reflexivity) ’ if α →β , then γ α → γβ (augmentation) ’ if α →β , and β → γ, then α → γ (transitivity) z These rules are ’ sound (generate only functional dependencies that actually hold) and ’ complete (generate all functional dependencies that hold).

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Example Example

z R = (A, B, C, G, H, I) F = { A → B A → C CG → H CG → I B → H } z 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 → CG I, and augmenting of CG → H to infer CGI → HI, and then transitivity

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Procedure for Computing F Procedure for Computing F++

z 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 f 1 and f 2 in F + if f 1 and f 2 can be combined using transitivity then add the resulting functional dependency to F + until F +^ does not change any further

NOTE : We shall see an alternative procedure for this task later

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Closure of Functional Dependencies (Cont.) Closure of Functional Dependencies (Cont.)

z We can further simplify manual computation of F +^ by using the following additional rules. ’ If α →β holds a nd α → γ holds, then α →β γ holds (union) ’ If α →β γ holds, then α →β holds and α → γ holds (decomposition) ’ If α →β holds a nd γβ → δ holds, then α γ → δ holds (pseudotransitivity) The above rules can be inferred from Armstrong’s axioms.

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Uses of Attribute Closure Uses of Attribute Closure

There are several uses of the attribute closure algorithm: z Testing for superkey: ’ To test if α is a superkey, we compute α+,^ and check if α+^ contains all attributes of R. z 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 z Computing closure of F ’ For each γ ⊆ R, we find the closure γ+, and for each S ⊆ γ+, we output a functional dependency γ → S.

Computing & Information Sciences CIS 560: Database System Concepts Friday, 29 Sep 2006 Kansas State University

Canonical CoverCanonical Cover

z Sets 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 } z 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