26
4 Normal Form Nathanael Chow CS 157A Fall 2006 Dr. Lee

4 Normal Form Nathanael Chow CS 157A Fall 2006 Dr. Lee

  • View
    215

  • Download
    2

Embed Size (px)

Citation preview

4 Normal Form

Nathanael ChowCS 157AFall 2006

Dr. Lee

Overview

● 1 NF● 2 NF● 3 NF● BCNF● 4 NF ● Conclusion

Database Normalization

● Each data in the database should represent once

● Purpose of normalization: to eliminate insert, update, and delete anomalies

First Normal Form (1 NF)

● All values in the columns are atomic (simple, indivisible). This is, they contain no repeating values.

● There are no repeating groups: two columns do not store similar information in the same table.

● Basically: 1 NF is to eliminate duplicate columns

1st Normal Form ExampleUn-normalized Students table:

Normalized Students table:102-8209-0467Smith123B124104-9102-8555James123A123Class2

Class1

AdvRoom

AdvName

AdvID

Student#

209-0467Smith123B124104-9555James123A123

102-8467Smith123B124

102-8555James123A123

Class#

AdvRoom

AdvName

AdvID

Student#

Second Normal Form (2 NF)

● A relation is in 2 NF if it is in 1 NF and every non-key attribute is fully functionally dependant on the primary key

2nd Normal Form ExampleStudents table

Registration table467Smith123B124555James123A123AdvRoomAdvNameAdvIDStudent#

209-0124104-9123

102-8124

102-8123Class#

Student#

Third Normal Form (3 NF)

● A relation is in 3 NF if it is 2 NF and no transitive dependencies exist.

● Transitive dependency is a functional dependency between non-key attribute

● Basically: 3 NF is to eliminate column not depend upon the primary key.

transitive dependency

Region Salesperson Name Cust_ID

transitivedependency

Salesperson Name Cust_ID

RegionSalesperson

Region Salesperson Name Cust_ID

Boyce-Codd Normal Form (BCNF)

● A relation is in BCNF if it is in 3 NF and every determinant is a candidate key; in other words, each determinant can be used as a primary key.

● Determinant: an attribute on which some other attribute is fully functionally dependent Ex: A --> B (A is called the determinant)

BCNF Example

● Given: R (A, B, C , D)● A --> B, C, D ● B --> A, C, D● C --> A , B, D● D --> A, B, C

BCNF Example (Cont...)

● Determinants: A, B, C, and D

● Candidate keys: A, B, C, and D

● Since all the determinants are candidate keys, this is BCNF.

4th Normal Form (4 NF)

● A relation is a 4 NF if it is BCNF and There is no multivalued dependency in the relation

or There are multivalued dependency but the attributes,

which are multivalued dependent on a specific attribute, are dependent between themselves

● What is a multivalued dependency (MVD)?

Definition of MVD

● A multivalued dependency X->-> Y is an assertion that if two tuples of a relation agree on all the attributes of X, then their components in the set of attributes Y may be swapped, and the result will be two tuples that are also in the relation

MVD Example

X Y Z

A B1 C1

A B2 C2

X Y ZA B1 C1A B2 C2

X ->-> Y

R(x, y, z)

MVD Example

X Y Z

A B1 C1

A B2 C2

X Y ZA B1 C1A B2 C2

X ->-> YA B2 C1A B1 C2

R(x, y, z)

4 NF Example

SingingArabic200

CookingEnglish200

CookingFrench100

PoliticKurdish100

TeachingEnglish 100

SkillLanguageEid

Assume the following relation:Employee (Eid:pk1, Language:pk2, Skill:pk3)

4 NF Example (conti...)

SingingArabic200CookingEnglish200CookingFrench100PoliticKurdish100TeachingEnglish 100SkillLanguageEid

Recall that a relation is in BCNF if all its determinant are candidate keys.

Because relation Employee has only one determinant (Eid, Language, Skill), which is the composite primary key.

Since the primary is a candidate key, R is in BCNF.

Assume that there is no MVD, then this relation is 4 NF.

4 NF Example (conti...)

Assume the following relation with multi-value dependency: Employee (Eid:pk1, Languages:pk2, Skills:pk3) Eid --->> Languages Eid --->> Skills

Languages and Skills are dependent.This says an employee speaks several languages and has several skills. However for each skill, a specific language is used when that skill is practiced.

4 NF Example (conti...)Thus employee 100 when she teaches, she uses English;

but when she cooks, she uses French. This relation is in fourth normal form.

SingingArabic200

CookingEnglish200

CookingFrench100

PoliticKurdish100

TeachingEnglish 100

SkillLanguageEid

Not 4 NF Example

Assume the following relation with multivalued dependency: Employee (Eid:pk1, Languages:pk2, Skills:pk3)

Eid --->> Languages Eid --->> Skills

Languages and Skills are independent.

Not 4 NF Example (conti...)

SingingArabic200CookingFrench100PoliticKurdish100TeachingEnglish 100SkillLanguageEid

Insertion anomaly: To insert row (200 English Cooking) we have to insert two extra rows (200 Arabic cooking), and (200 English Singing) otherwise the database will be inconsistent.

SingingEnglish200

CookingArabic200

CookingEnglish200SingingArabic200

TeachingKurdish100PoliticsEnglish100

PoliticsKurdish100TeachingEnglish100

SkillLanguage

Eid

Not 4 NF Example (conti...)Here is the table after the insertion:

Conclusion of Steps in Conclusion of Steps in NormalizationNormalization

References

● http://www.cs.sjsu.edu/faculty/lee/cs157/cs157a.html

● http://www.cs.sjsu.edu/faculty/lee/cs157/cs157alecturenotes.htm