Recall
• Why do we need transactions?
• What is rollback and commit?
Introduction to MySQL
Database Normalization
Day 2,Week 7
Relevance of normalization
• We could have store all the data in a
single table like
• But there are several issues arise ...
Relevance of normalization
• We could have store all the data in a
single table likeEmp_id Emp_name Emp_age Emp_email Fk_i...
Relevance of normalization
• We could have store all the data in a
single table likeEmp_id Emp_name Emp_age Emp_email Fk_i...
Normalization
• Normalization is the process of moving
data into related tables
• Will save data dependency and
redundancy...
Types of Normalization
• There are several levels of
normalization
– 1st Normalization
– 2nd Normalization
– 3rd Normaliza...
First Normal Form
First Normal Form
–Each field contains the smallest
meaningful value
– The table does not contain repeating
groups of fiel...
Table violating 1st Normal Form
Company (pk) Branches
Baabte Cochin, Calicut
baabtra Calicut,Trivandrum
It really is a bad...
Table violating 1st Normal Form
Company (Pk) Branche1 Branch2
Baabte Cochin Calicut
baabtra Calicut Trivandrum
It still in...
Table conforming to 1st Normal
Form
Company (pk) Branch (pk)
Baabte Cochin
Baabte Calicut
baabtra Calicut
baabtra Trivandr...
Second
Normalisation
Second Normalisation
–usually used in tables with a multiple-
field primary key (composite key)
–each non-key field relate...
Table violating 2nd Normal Form
Employee (pk) Skill (pk) WorkLocation
John IOS programmer Calicut
Mathew Java programmer C...
Table violating 2nd Normal Form
Employee (pk) Skill (pk) WorkLocation
John IOS programmer Calicut
Mathew Java programmer C...
Table conforming to 2nd Normal
Form
Employee (pk) Skill (pk)
John IOS programmer
Mathew Java programmer
Thomas Android pro...
Third
Normalisatio
n
Third Normal Form
• Usually used in tables with a single field primary
key
– records do not depend on anything other than
...
EMPNO
(Primary Key)
FIRSTNAME LASTNAME WORKDEPTNO DEPTNAME
000290 John Parker OP11 Operations
000320 Ramlal Mehta SE21 Sof...
EMPNO
(Primary Key)
FIRSTNAME LASTNAME WORKDEPTNO DEPTNAME
000290 John Parker OP11 Operations
000320 Ramlal Mehta SE21 Sof...
Table conforming to 3rd Normal
Form
EMPNO
(Primary Key)
FIRSTNAME LASTNAME WORKDEPTNO
000290 John Parker OP11
000320 Ramla...
Questions?
“A good question deserve a good
grade…”
End of day2,Week 7
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.co...
Contact
Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, N...
Upcoming SlideShare
Loading in …5
×

Introduction to mysql part 6

397
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
397
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
33
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction to mysql part 6

  1. 1. Recall • Why do we need transactions? • What is rollback and commit?
  2. 2. Introduction to MySQL Database Normalization Day 2,Week 7
  3. 3. 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 dk@gmail.com Are Manager Handles all the district level operations 1001 Aneesh 23 an@gmail.com Sales person Will increase sales and ensure customer satisfaction 1002 Naveen 25 nn@gmail.com Sales person Will increase sales and ensure customer satisfaction 1003 Jacob 25 dpk@gmail.com Administrator Handles all the district level operations
  4. 4. Relevance of normalization • We could have store all the data in a single table likeEmp_id Emp_name Emp_age Emp_email Fk_int_designation Vchr_Desig_roles 1000 Deepak 45 dk@gmail.com Are Manager Handles all the district level operations 1001 Aneesh 23 an@gmail.com Sales person Will increase sales and ensure customer satisfaction 1002 Naveen 25 nn@gmail.com Sales person Will increase sales and ensure customer satisfaction 1003 Jacob 25 dpk@gmail.com 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
  5. 5. Relevance of normalization • We could have store all the data in a single table likeEmp_id Emp_name Emp_age Emp_email Fk_int_designation Vchr_Desig_roles 1000 Deepak 45 dk@gmail.com Are Manager Handles all the district level operations 1001 Aneesh 23 an@gmail.com Sales person Will increase sales and ensure customer satisfaction 1002 Naveen 25 nn@gmail.com Sales person Will increase sales and ensure customer satisfaction 1003 Jacob 25 dpk@gmail.com 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
  6. 6. 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
  7. 7. Types of Normalization • There are several levels of normalization – 1st Normalization – 2nd Normalization – 3rd Normalization
  8. 8. First Normal Form
  9. 9. 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
  10. 10. 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
  11. 11. 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.
  12. 12. 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
  13. 13. Second Normalisation
  14. 14. 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
  15. 15. 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 }
  16. 16. 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. Ie WorkLocation depends only on Employee and doesn’t depend on Skill (partial dependency) Primary key= { Employee,Skill }
  17. 17. 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
  18. 18. Third Normalisatio n
  19. 19. 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.
  20. 20. 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
  21. 21. 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
  22. 22. 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.
  23. 23. Questions? “A good question deserve a good grade…”
  24. 24. End of day2,Week 7
  25. 25. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  26. 26. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com

×