5 normal forms in relational database theory

30
FIVE NORMAL FORMS IN RELATIONAL DATABASE THEORY AIME

Upload: pankamol-srikaew

Post on 15-Apr-2017

293 views

Category:

Software


7 download

TRANSCRIPT

Page 1: 5 normal forms in relational database theory

FIVE NORMAL FORMS IN RELATIONAL DATABASE THEORY- AIME

Page 2: 5 normal forms in relational database theory

TODAY’s CONTENT

Why we have to learn database normalization Bad Relational Database Design – unnormalized 5 Normalization Forms Better Relational Database Design - normailized Conclusion

Page 3: 5 normal forms in relational database theory

Why normalization?

Database Design Minimize Data Redundancy from UPDATE ANOMALIES

UPDATE ANOMALIES Insertion anomalies Deletion anomalies Modification anomalies

Page 4: 5 normal forms in relational database theory

Update Anomalies

Page 5: 5 normal forms in relational database theory

Insert?

Page 6: 5 normal forms in relational database theory

Insert? DATA REDUNDANCY!

Page 7: 5 normal forms in relational database theory

Delete?

Page 8: 5 normal forms in relational database theory

Delete? OTHER IMPORTANT INFORMATIONS MIGHT BE DELETED

Page 9: 5 normal forms in relational database theory

Modify?

Page 10: 5 normal forms in relational database theory

Modify? MIGHT CAUSE INCONSISTENCY PROBLEM

Page 11: 5 normal forms in relational database theory

BAD DATABASE DESIGN

Page 12: 5 normal forms in relational database theory

Normalization

Unnormalization form

1st normalization form

2nd normalization

form

3rd normalization form

4th normalization form

5th normalization form

Remove repeating

group

Remove partial

dependencies

Remove transitive

dependencies

Remove remaining

anomalies from functional

dependencies

Remove multi-value

dependencies

join dependencies

Page 13: 5 normal forms in relational database theory

Unnormalized Form

Page 14: 5 normal forms in relational database theory

Unnormalized Form to 1st Normalized Form

Page 15: 5 normal forms in relational database theory

1st Normalized Form problem

Data Redundancy Might cause inconsistency problem

Page 16: 5 normal forms in relational database theory

Move to 2nd Normalized Form

Conditions It’s already in 1st normalized form All attributes have fully functional dependency with primary key, NOT partial dependency Get rid of Partial dependencies

Page 17: 5 normal forms in relational database theory

Move to 2nd Normalized Form

Partial Dependency Non-prime field(s) depends on one primary key Student_ID + Course_ID Firstname, Surname, Cum.GPA, Position_ID, Position, Scholarship, Course_ID, Course, Credit, Grade, Lecturer_ID,

Lecturer Student_ID Firstname, Surname, Cum.GPA, Position_ID, Position, Scholarship Course_ID Course, Credit, Grade, Lecturer_ID, Lecturer Student_ID + Course_ID Grade

PK PK

PK: Primary KeyFK: Foreign Key

FK FK

Page 18: 5 normal forms in relational database theory

2nd Normalized Form

Separate into relation tables...

PK

PK

Student Relation

Course Relation

FK FK

Student-Course Relation Table

Page 19: 5 normal forms in relational database theory

Move to 3rd Normalized Form

Conditions It’s already in 2nd normalized form Get rid of Transitive Dependency

PK

PK

Student Relation

Course Relation

FK FK

Student-Course Relation Table

Page 20: 5 normal forms in relational database theory

Move to 3rd Normalized Form

Transitive Dependency Other attributes, those are not a primary key, cannot define the value of

other attributes

PK

Student Relation

Non-PK

Page 21: 5 normal forms in relational database theory

3rd Normalized Form

Separate into relation tables...

PK

PK

Student Relation

Course Relation

FK FK

Student-Course Relation

FKPK Position Relation

Page 22: 5 normal forms in relational database theory

3rd Normalized Form

Separate into relation tables...

PKStudent Relation

FK FK

Student-Course Relation

FKPK Position Relation

PK Course Relation FK PK Lecturer Relation

Page 23: 5 normal forms in relational database theory

Move to 4th Normalized Form

Conditions It’s in 3rd normalized form Get rid of multi-valued dependencies

PK

PK

Student Relation

Course Relation

FK FK

Student-Course Relation

FKPK Position Relation

FK PK Lecturer Relation

Page 24: 5 normal forms in relational database theory

Move to 4th Normalized Form

Conditions It’s in 3rd normalized form Get rid of multi-valued dependencies

PK

PK

Student Relation

Course Relation

FK FK

Student-Course Relation

FKPK Position Relation

FK PK Lecturer Relation

Add Research for each lecturer

Page 25: 5 normal forms in relational database theory

Move to 4th Normalized Form

Multi-valued Dependencies AB; Lecturer_IDLecturer AC; Lecturer_IDResearch But B and C is independent

A B C

PK

PK

Lecturer Relation

Lecturer-Research Relation

Page 26: 5 normal forms in relational database theory

Final Form – 4th Normalized FormPK

PK

Student Relation

Course Relation

FK FK

Student-Course Relation

FKPK Position Relation

FK PK Lecturer Relation PK Lecturer-Research Relation

Page 27: 5 normal forms in relational database theory

5th Normalized Form

Separate more relation and it’s able to join back without spurious tuple occurance

No spurious tuple

PK Position RelationPK Position Relation

Page 28: 5 normal forms in relational database theory

Supurios Tuple Example

????

Spurious tuple exist!!

Page 29: 5 normal forms in relational database theory

PK

PK

Student Relation

Course Relation

FK FK

Student-Course Relation

FKPK Position Relation

FK PK Lecturer Relation PK Lecturer-Research Relation

OLD version

NEW version

Page 30: 5 normal forms in relational database theory

Conclusion

The purpose of normalization is to Reduce data redundacy Prevent data inconsistency

Trade-off Performance

The factors to be considered while normalization Single-valued vs Multivalued Dependencies

Partial dependency Transitive dependency Functional dependency Multivalued dependency

Key and non-Key field relationship