Database normalisation

Post on 20-May-2015

327 views 0 download

Tags:

Transcript of Database normalisation

Anu. Sanusdhar4@gmail.comwww.facebook.com/Anu

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

profilename

DATABASE NORMALIZATION

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

DATABASE NORMALIZATION

LEVELS OF NORMALIZATION

SOLVED EXAMPLE

CONTENTS

DATABASE NORMALIZATION

What is normalization????

Why normalize the database???

Strength and drawback of normalization..!!!

What is actually normalization???

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

Why normalize database????

Minimizing redundancyAccuracyPerformance

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

Strength:Reduces RedundancyReduces errors

Drawback:No of tables increasesComplexity increases

LEVELS OF NORMALIZATION

1NF2NF3NF BCNF 4NF 5NF DKNF

Redundancy

Num

ber o

f Tab

les

Com

plex

ity

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

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

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

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

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

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

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.

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

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

Let us first list the required tables:

Login_tableUser_tableUser_type_tableExam_tableExam_qstn_tableQstn_option_tableStud_answer_table

SOLVING THE PROBLEM

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

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

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

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

THANK YOU...

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.

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

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: info@baabtra.com