+ All Categories
Home > Technology > Chapter 6 database normalisation

Chapter 6 database normalisation

Date post: 27-Jul-2015
Category:
Upload: baabtracom-no-1-supplier-of-quality-freshers
View: 268 times
Download: 2 times
Share this document with a friend
Popular Tags:
22
Introduction to MySQL Database Normalization Day 2
Transcript
Page 1: Chapter 6  database normalisation

Introduction to MySQLDatabase Normalization

Day 2

Page 2: Chapter 6  database normalisation

Relevance of normalization

• We could have store all the data in a single table like

• But there are several issues arise here

Emp_id Emp_name Emp_age Emp_email Fk_int_designation

Vchr_Desig_roles

1000 Deepak 45 [email protected]

Are Manager Handles all the district level operations

1001 Aneesh 23 [email protected] Sales person Will increase sales and ensure customer satisfaction

1002 Naveen 25 [email protected]

Sales person Will increase sales and ensure customer

satisfaction

1003 Jacob 25 [email protected]

Administrator Handles all the district level operations

Page 3: Chapter 6  database normalisation

Relevance of normalization

• We could have store all the data in a single table like

Emp_id Emp_name Emp_age Emp_email Fk_int_designation

Vchr_Desig_roles

1000 Deepak 45 [email protected]

Are Manager Handles all the district level operations

1001 Aneesh 23 [email protected] Sales person Will increase sales and ensure customer satisfaction

1002 Naveen 25 [email protected] Sales person Will increase sales and ensure customer satisfaction

1003 Jacob 25 [email protected]

Administrator Handles all the district level operations

Here designation is repeated for all the rows and where ever it repeats the designation role also has to repeat. This redundancy takes a lot of space to store and

is inefficient

Page 4: Chapter 6  database normalisation

Relevance of normalization

• We could have store all the data in a single table like

Emp_id Emp_name Emp_age Emp_email Fk_int_designation

Vchr_Desig_roles

1000 Deepak 45 [email protected]

Are Manager Handles all the district level operations

1001 Aneesh 23 [email protected] Sales person Will increase sales and ensure customer satisfaction

1002 Naveen 25 [email protected] Sales person Will increase sales and ensure customer satisfaction

1003 Jacob 25 [email protected]

Administrator Handles all the district level operations

Suppose if i want to modify the roles of any designation, i will have to do the same for all records in the table. Its time consuming and not an effective way to follow

Page 5: Chapter 6  database normalisation

Normalization• Normalization is the process of moving data into related

tables

• Will save data dependency and redundancy

• Save typing of repetitive data

• Reduce disk space

Page 6: Chapter 6  database normalisation

Types of Normalization

• There are several levels of normalization– 1st Normalization– 2nd Normalization– 3rd Normalization

Page 7: Chapter 6  database normalisation

First Normal Form

Page 8: Chapter 6  database normalisation

First Normal Form– Each field contains the smallest meaningful value– The table does not contain repeating groups of fields or

repeating data within the same field

To attain 1st normalized form what you have to do is•Create a separate field/table for each set of related data. •Identify each set of related data with a primary key

Page 9: Chapter 6  database normalisation

Table violating 1st Normal Form

Company (pk) Branches

Baabte Cochin, Calicut

baabtra Calicut,Trivandrum

It really is a bad setup that we are storing multiple values in a single column. For a table to be in 1st normalised form it should only have atomic values

Page 10: Chapter 6  database normalisation

Table violating 1st Normal Form

Company (Pk) Branche1 Branch2

Baabte Cochin Calicut

baabtra Calicut Trivandrum

It still in a bad set up , as we should not have multiple columns describing the same property of an entity.

Page 11: Chapter 6  database normalisation

Table conforming to 1st Normal Form

Company (pk) Branch (pk)

Baabte Cochin

Baabte Calicut

baabtra Calicut

baabtra Trivandrum

We have resulted in a 1st normalised table with primary key consists of two columns

Page 12: Chapter 6  database normalisation

Second Normalisation

Page 13: Chapter 6  database normalisation

Second Normalisation

– usually used in tables with a multiple-field primary key (composite key)

– each non-key field relates to the entire primary key– any field that does not relate to the primary key is placed

in a separate table• To attain 1st normalized form what you have to do is

•eliminate redundant data in a table •Create separate tables for sets of values that apply to

multiple records

Page 14: Chapter 6  database normalisation

Table violating 2nd Normal Form

Employee (pk) Skill (pk) WorkLocation

John IOS programmer Calicut

Mathew Java programmer Cochin

Thomas Android programmer

Trivandrum

Alex PHP programmer Banglore

Ram Java programmer Mumbai

John PHP programmer Delhi

Soozan doNet programmer Calicut

Primary key= { Employee,Skill }

Page 15: Chapter 6  database normalisation

Table violating 2nd Normal Form

Employee (pk) Skill (pk) WorkLocation

John IOS programmer Calicut

Mathew Java programmer Cochin

Thomas Android programmer

Trivandrum

Alex PHP programmer Banglore

Ram Java programmer Mumbai

John PHP programmer Delhi

Soozan doNet programmer Calicut

Here non key attribute do not fully depends on compete primary key. IeWorkLocation depends only on Employee and doesn’t depend on Skill (partial

dependency)

Primary key= { Employee,Skill }

Page 16: Chapter 6  database normalisation

Table conforming to 2nd Normal Form

Employee (pk)

Skill (pk)

John IOS programmer

Mathew Java programmer

Thomas Android programmer

Alex PHP programmer

Ram Java programmer

John PHP programmer

Soozan doNet programmer

Employee (pk)

WorkLocation

John Calicut

Mathew Cochin

Thomas Trivandrum

Alex Banglore

Ram Mumbai

John Delhi

Soozan Calicut

Page 17: Chapter 6  database normalisation

Third Normalisation

Page 18: Chapter 6  database normalisation

Third Normal Form• Usually used in tables with a single field primary key

--records do not depend on anything other than a table's primary key – each non-key field is a fact about the key– Values in a record that are not part of that record's key do

not belong in the table. In general, any time the contents of a group of fields may apply to more than a single record in the table, consider placing those fields in a separate table.

Page 19: Chapter 6  database normalisation

EMPNO (Primary Key)

FIRSTNAME LASTNAME WORKDEPTNO DEPTNAME

000290 John Parker OP11 Operations

000320 Ramlal Mehta SE21 Software Support

000310 Maude Setright OP11 Operations

Table violating 3rd Normal Form

Page 20: Chapter 6  database normalisation

EMPNO (Primary Key)

FIRSTNAME LASTNAME WORKDEPTNO DEPTNAME

000290 John Parker OP11 Operations

000320 Ramlal Mehta SE21 Software Support

000310 Maude Setright OP11 Operations

Table violating 3rd Normal Form

Here all the fields are not completely depend on Primary key.Ie Dept Name column only depends on DeptNo.And deptno depends on the EMPNO.

Ie its a transitive dependency. Which should be avoided

Page 21: Chapter 6  database normalisation

Table conforming to 3rd Normal Form

EMPNO (Primary Key)

FIRSTNAME LASTNAME WORKDEPTNO

000290 John Parker OP11

000320 Ramlal Mehta SE21

000310 Maude Setright OP11

WORKDEPTNO DEPTNAME

OP11 Operations

SE21 Software Support

OP11 Operations

Here all the fields are completely depend on Primary key.

Page 22: Chapter 6  database normalisation

End of Day2


Recommended