normalization - mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/ps/2017/week11/...normal forms...

17
NORMALIZATION 26th-27th November 2015 Gözde ALP

Upload: others

Post on 18-Jul-2021

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

NORMALIZATION

26th-27th November 2015

Gözde ALP

Page 2: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

CONTENT

Normal Forms

FD (Functional Dependencies)

Finding Candidate Key

Exercises

Page 3: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

NORMAL FORMS

1NF(First Normal Form): An entity is in 1NF

when it contains no repeating groups of data.

2NF(Second Normal Form): When it is in 1NF

and when all of its attributes are fully

dependent on its primary key.

3NF(Third Normal Form): An entity type is in

3NF when it is in 2NF and when all of its

attributes are directly dependent on the

primary key

Page 4: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

FD (FUNCTIONAL DEPENDENCIES)

FDs are constraints that are derived from the

meaning and interrelationships of the data

attributes

ID ‐> email, city, country, surname

Page 5: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

1NF

All the attributes in a relation must have atomic

domains. The values in an atomic domain are

indivisible units.

Multivalued attributes

1NF

Page 6: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

2NF Every non-prime attribute should be fully functionally

dependent on prime key attribute. Prime key attributes are

Stu_ID and Proj_ID. Stu_Name and Proj_Name must be

dependent upon both and not on any of the prime key attribute

individually.

Partial dependency

2NF

Page 7: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

3NF Stu_ID is the key and only prime key attribute. We find

that City can be identified by Stu_ID as well as Zip

itself. Neither Zip is a superkey nor is City a prime

attribute. Additionally, Stu_ID → Zip → City, so there

exists transitive dependency.

3NF

Page 8: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

EXERCISE 1

Enrollment( studentID, courseCode, sName, sSurname,

courseName, grade)

FD1: studentID sName, sSurname

FD2: courseCodecourseName

FD3: studentID, courseCodegrade

Funtional dependencies of Enrollment table is illustrated below.

a. What is the normal form of this relation?

Page 9: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

EXERCISE 1

b. Decompose the relations into 3NF step by

step.

Page 10: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

FINDING CANDIDATE KEY

If the prime attribute is not given, how can we

find candidate key?

By help of transitive closure

Page 11: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

EXERCISE 2

Find candidate key of the following relation.

R(A,B,C,D,E,F)

FD1: AC

FD2: CD

FD3: DB

FD4: EF

Page 12: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

EXERCISE 3

Find candidate key of the following relation.

R(A,B,C,D)

FD1: CD

FD2: CA

FD3: BC

Page 13: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

EXERCISE 4

Find candidate key of the following relation.

R(A,B,C,D,E,F)

FD1: AB,C,D,E,F

FD2: B,CA,D,E,F

FD3: BF

FD4: DE

Page 14: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

EXERCISE 5

What is the normal form of this relation?

Decompose the relation into 3NF step by step

according to the candidate key you find in 4th

exercise.

R(A,B,C,D,E,F)

FD1: B,CA,D,E,F

FD2: BF

FD3: DE

Page 15: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

EXERCISE 6

Find the candidate key of following relation.

R(A,B,C,D)

FD1: A,BC

FD2: BD

What is the normal form of this relation?

Decompose the relation into 3NF step by step.

Page 16: Normalization - Mimozamimoza.marmara.edu.tr/~gozde.alp/cse355/PS/2017/week11/...NORMAL FORMS 1NF(First Normal Form): An entity is in 1NF when it contains no repeating groups of data

EXERCISE 7

R(A,B,C,D,E,F,G,H,I,J,K,M)

FD1: AJ,K

FD2: BD,E

FD3: FG,H

FD4: IC

Assume key is ABC. What is the normal form of

this relation?

Decompose the relation into 3NF step by step.