Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Normalization

4,702 views

Published on

Published in: Technology

Normalization

  1. 1. Why be Normal? An Introduction To Normalization http://joind.in/3436
  2. 2. About Me• Ligaya Turmelle• Senior Technical Support Engineer - MySQL• 9 years• I <3 Databases
  3. 3. Disclaimer
  4. 4. Questions• Who works with databases?• Who has had to design a database?• Who has no idea what normalization is but has heard about it?• ERD?• Anyone heard of denormalization?
  5. 5. So what exactly is Normalization?
  6. 6. process oforganizing your data
  7. 7. So why do we use Normalization?
  8. 8. reduce redundanciesand organize the relationships
  9. 9. Advantages• stored as small atomic pieces• saves space• increases speed• reduces data anomalies• makes for easier maintenance
  10. 10. So what then is this1NF, 2NF, 3NF, etc.?
  11. 11. This refers toNormal forms (NF)
  12. 12. Normal Forms• Normal forms are “standardized” rules• Each form builds off the last one• The higher the number the more normalized the data is
  13. 13. So lets go over themost common forms
  14. 14. Example Data student emergency school parents student age classroom teacher grade level Name contact yearJohn and Mary John Smith John Smith 10 C110 Ms. Brown 2010 6 Smith Jr. Mary Smith 9 C80 Mr Green 2009 5 April John Smith 10 C110 Ms. Brown 2010 6 Smith Mary Smith 9 A25 Mr Baker 2009 5 Julie Dave Harris Dave Harris 6 A10 Mr Jones 2010 3 Harris
  15. 15. Base table we will start with
  16. 16. 1NF
  17. 17. First Normal Form• remove “repeating groups”
  18. 18. Example Data student emergency school parents student age classroom teacher grade level Name contact yearJohn and Mary John Smith John Smith 10 C110 Ms. Brown 2010 6 Smith Jr. Mary Smith 9 C80 Mr Green 2009 5 April John Smith 10 C110 Ms. Brown 2010 6 Smith Mary Smith 9 A25 Mr Baker 2009 5 Julie Dave Harris Dave Harris 6 A10 Mr Jones 2010 3 Harris
  19. 19. Example Data student emergency school parents student age classroom teacher grade level Name contact yearJohn Smith John Smith Jr. John Smith 10 C110 Ms. Brown 2010 6Mary Smith John Smith Jr. John Smith 10 C110 Ms. Brown 2010 6John Smith John Smith Jr. Mary Smith 9 C80 Mr Green 2009 5Mary Smith John Smith Jr. Mary Smith 9 C80 Mr Green 2009 5John Smith April Smith John Smith 10 C110 Ms. Brown 2010 6Mary Smith April Smith John Smith 10 C110 Ms. Brown 2010 6John Smith April Smith Mary Smith 9 A25 Mr Baker 2009 5Mary Smith April Smith Mary Smith 9 A25 Mr Baker 2009 5Dave Harris Julie Harris Dave Harris 6 A10 Mr Jones 2010 3
  20. 20. First Normal Form• remove repeating groups• a primary key can be defined
  21. 21. What is a primary key?
  22. 22. it can UNIQUELYidentify any row in a table
  23. 23. Base table we will start with
  24. 24. Example Data student emergency school parents student age classroom teacher grade level Name contact yearJohn Smith John Smith Jr. John Smith 10 C110 Ms. Brown 2010 6Mary Smith John Smith Jr. John Smith 10 C110 Ms. Brown 2010 6John Smith John Smith Jr. Mary Smith 9 C80 Mr Green 2009 5Mary Smith John Smith Jr. Mary Smith 9 C80 Mr Green 2009 5John Smith April Smith John Smith 10 C110 Ms. Brown 2010 6Mary Smith April Smith John Smith 10 C110 Ms. Brown 2010 6John Smith April Smith Mary Smith 9 A25 Mr Baker 2009 5Mary Smith April Smith Mary Smith 9 A25 Mr Baker 2009 5Dave Harris Julie Harris Dave Harris 6 A10 Mr Jones 2010 3
  25. 25. 2NF
  26. 26. Second Normal Form• meet all requirements of 1NF• isolate repeated subsets of data
  27. 27. Class
  28. 28. Class
  29. 29. Contact
  30. 30. Contact
  31. 31. And that then leaves us with...
  32. 32. And that then leaves us with...
  33. 33. Second Normal Form• meet all requirements of 1NF• isolate related data• create the relationships
  34. 34. Our Tables Right Now
  35. 35. Student to Contact relationship
  36. 36. Student to Contact relationship
  37. 37. Student to Class relationship
  38. 38. Student to Class relationship
  39. 39. The tables andrelationships
  40. 40. Example Data StuClassStudent studentName class_idstudentName studentAge John Smith Jr 1John Smith Jr 10 John Smith Jr 2 April Smith 10 Julie Harris 6 April Smith 1 April Smith 3 Julie Harris 4Classclass_id classroom teacher schoolYear gradeLevel 1 C110 Ms. Brown 2010 6 2 C80 Mr. Green 2009 5 3 A25 Mr. Baker 2009 5 4 A10 Mr. Jones 2010 3
  41. 41. Example Data StuContactStudent studentName contactNamestudentName studentAge John Smith Jr John SmithJohn Smith Jr 10 April Smith 10 John Smith Jr Mary Smith Julie Harris 6 April Smith John Smith April Smith Mary SmithContact Julie Harris Dave HarriscontactName parent contactPhone contactEmail contactAddress John Smith Y 123-555-9876 john@blah.com 1 Main StMary Smith Y 123-555-2947 mary@blah.com 1 Main StDave Harris Y 123-555-3456 dave@work.cm 5 Baker Rd
  42. 42. 3NF
  43. 43. Third Normal Form• meet all requirements of 2NF• pull out data that is not dependent on the primary key
  44. 44. The tables andrelationships
  45. 45. The tables andrelationships
  46. 46. The tables andrelationships
  47. 47. reminderWe are looking for data that is not dependenton the primary key, so we can extract that out
  48. 48. moving to 3NF
  49. 49. and the relationship between them
  50. 50. You can go tohigher NF, if you really want
  51. 51. Generally speaking there is no need
  52. 52. Knowing what you know now...
  53. 53. can you guess whatDenormalization is now?
  54. 54. Reasons for Denormalization• SELECT with JOINs • Lots of JOINs• Summarize information Normalize first and then only denormalize when you have to.
  55. 55. Questions?
  56. 56. Thank Youhttp://joind.in/3436

×