Database normalisation

27

Transcript of Database normalisation

Page 1: Database normalisation
Page 2: Database normalisation

Anu. [email protected]/Anu

Sasidharantwitter.com/usernamein.linkedin.com/in/

profilename

DATABASE NORMALIZATION

Page 3: Database normalisation

Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

Page 4: Database normalisation

DATABASE NORMALIZATION

LEVELS OF NORMALIZATION

SOLVED EXAMPLE

CONTENTS

Page 5: Database normalisation

DATABASE NORMALIZATION

What is normalization????

Why normalize the database???

Strength and drawback of normalization..!!!

Page 6: Database normalisation

What is actually normalization???

The process of analyzing a given relational schema based on their functional dependencies and primary keys.

Page 7: Database normalisation

Why normalize database????

Minimizing redundancyAccuracyPerformance

Page 8: Database normalisation

Strength And Drawback of Databases...!!!!

Strength:Reduces RedundancyReduces errors

Drawback:No of tables increasesComplexity increases

Page 9: Database normalisation

LEVELS OF NORMALIZATION

1NF2NF3NF BCNF 4NF 5NF DKNF

Redundancy

Num

ber o

f Tab

les

Com

plex

ity

Page 10: Database normalisation

FIRST NORMAL FORM-1NF

A table is considered to be in 1NF if all the fields containonly scalar values

Example (Not 1NF)

Pk_Int_Book_id Vchr_bookname Vchr_author

111 Basic Electrical and Electronics Engineering

Storey,Huggies,Tomasi

121 EVS Venugopal,Vinod

Page 11: Database normalisation

After performing 1NF

Pk_int_book_id Vchr_Bookname Vchr_author

111 Basic Electrical and Electronics Engineering

Storey

111 Basic Electrical and Electronics Engineering

Huggies

111 Basic Electrical and Electronics Engineering

Thomasi

121 EVS Vinod

121 EVS Venugopal

Page 12: Database normalisation

Second Normal Form

For a table to be in 2NF, there are two requirements:

The database is in first normal form

All non_key attributes in the table must be functionally dependent on the entire primary key

Page 13: Database normalisation

Second Normal Form- Example

Database not in 2NF:

Pk_Vchr_Emp_name Pk_Vchr_emp_desig Int_Emp_Sal Vchr_emp_address

Paul Manager 60000 121,PK street,Mumbai

Ram Clerk 5000 111/114, Arumugam street, Chennai

Primary key : {vchr_emp_name,vchr_emp_desig}

Here the employee salary is dependant on both primary keys.Employee address is not dependant on employee designation.Hence it is not in 2NF

Page 14: Database normalisation

Second Normal Form- Example

Database after performing 2NF:Pk_Vchr_Emp_name

Pk_Vchr_emp_desig

Int_Emp_Sal

Paul Manager 60000

Ram Clerk 5000

Pk_Vchr_Emp_name Vchr_Emp_address

Paul 121,PK street,Mumbai

Ram 111/114, Arumugam street, Chennai

Page 15: Database normalisation

THIRD NORMAL FORM

For a table to be in 3NF, there are two requirements:

The table should be second normal form

No attribute is transitively dependent on the primary key

All non key attributes of a table must be functionally dependent on a candidate key.

There must be no interdependencies among non-key attributes

Page 16: Database normalisation

Third Normal Form- Example

Database not in 3NF:Pk_int_stud_id Vchr_stud_name Int_class_id Vchr_class_name

3457 Ashish 101 CS5

4332 Abhay 121 EC6

Primary key : {pk_vchr_emp_name}

Here Student name , and class_id depends on primary key pk_int_stud_id. The class name is but more dependant on the class_id (non-key) than stud_id.So there is a transitive dependency. Hence not in 3NF.

Page 17: Database normalisation

Third Normal Form- Example

Database after performing 3NF:Pk_int_stud_id Vchr_stud_name Int_class_id

3457 Ashish 101

4332 Abhay 121

Pk_Int_class_id Vchr_class_name

101 CS5

121 EC6

Page 18: Database normalisation

AN EXAMPLE TO SOLVEExam Management System-----------------------------------Users:

Admin Student

Admin ---------

Login View Profile Edit Profile Facility to manage student Facility to manage exam

Student----------

Attend exams View mark

Page 19: Database normalisation

Let us first list the required tables:

Login_tableUser_tableUser_type_tableExam_tableExam_qstn_tableQstn_option_tableStud_answer_table

SOLVING THE PROBLEM

Page 20: Database normalisation

Pk_int_login_id Vchr_username Vchr_password

1 Administrator Admin

2 Ashish Ashish123

3 Abhay abhay123

Login_table

User_table

Pk_int_user_id

Vchr_uname

Fk_int_ login_id

Dat_dob Vchr_place

Bln_status int_user_ type

1 Pratap 1 1867-05-01 Calicut 1 1

2 Ashish 2 1993-02-01 Banglore 1 2

3 Abhay 3 1992-03-11 Chennai 1 2

Pk_int_ type_id

Vchr_ utype

1 Admin

2 Student

User_type_table

Page 21: Database normalisation

Pk_int_exam_id Vchr_exam_name int_exam_duration(in hrs)

101 Basic C programming Test

1

102 Cpp Evaluation test 1

Exam_table

Exam_qstn_table

Pk_int_qstn_id Fk_int_exam_id Vchr_question Vchr_answer Int_marks

1111 101 Code1 21 5

1112 101 Code2 11122133 10

1113 102 Code3 131 5

1114 102 Code4 3333 10

Page 22: Database normalisation

Question_option_table

Pk_int_option_id Fk_int_qstn_id Vchr_option

1 1111 21

2 1111 22

3 1111 25

4 1112 11122133

5 1112 0

6 1112 11100000

7 1113 131

8 1113 100

9 1113 1

10 1114 3333

11 1114 0

12 1114 2222

Page 23: Database normalisation

Student_answer_table

Pk_int_answer_id

Fk_int_qstn_id fk_int_user_id Vchr_stud_answer

Int_mark_scored

116 1111 2 22 0

117 1112 2 11122133 10

118 1113 2 131 5

119 1114 2 3333 10

120 1111 3 21 5

121 1112 3 11122133 10

122 1113 3 131 5

123 1114 3 0 0

Page 24: Database normalisation

THANK YOU...

Page 25: Database normalisation

Want to learn more about programming or Looking to become a good programmer?

Are you wasting time on searching so many contents online?

Do you want to learn things quickly?

Tired of spending huge amount of money to become a Software professional?

Do an online course @ baabtra.com

We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.

Page 26: Database normalisation

Follow us @ twitter.com/baabtra

Like us @ facebook.com/baabtra

Subscribe to us @ youtube.com/baabtra

Become a follower @ slideshare.net/BaabtraMentoringPartner

Connect to us @ in.linkedin.com/in/baabtra

Thanks in advance.

www.baabtra.com | www.massbaab.com |www.baabte.com

Page 27: Database normalisation

Contact Us

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode

Start up VillageEranakulam,Kerala, India.

Email: [email protected]