Agenda and Objectives Agenda ▫Examine normalized and non-normalized ERDs/Tables Objectives ▫Given an ERD, you will be able to determine whether or not it is in 3NF. ▫Given a non-normalized ERD (or database table), you will be able to revise it to make it 3NF compliant. Resource ▫Normalized_ERDs.pptx
Normalizing Your Database Model IS 310 Dr. Jean A. Pratt
Related Terminology Normalization First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF) 1NF: No repeating groups; 1 value/cell 2NF: No partial dependencies 3NF: No transitive dependencies
First Normal Form (1NF) Only those attributes that describe the entity are included in that entity Each entity has a primary key (PK) Each attribute is the smallest unit that would be included in a query Data is not repeated in different entities Each attribute would contain a single value in the database table cell Redundant data is minimized
Multivalued Attributes: AVOID Multivalued attribute ▫An attribute that may take on more than one value for each entity instance Examples Skill is a multivalued attribute of Employee Color may be a multivalued attribute of ToyBlock Dependent is a multivalued attribute of Employee Phone/fax number is a multivalued attribute of Employee Repeating group ▫A set of multivalued attributes that are logically related—associated with the same entity instance Dependent address for each dependent of employee
Example of (almost) 1NF ERD Note that we will still have redundant data (although not multivalued) if students live at the same address. We’ll want to remove that redundancy later.
Resulting 1NF Table STUDENT Student_IDFirst NameLast NameStreetCityStateZipPhone 12345JoeJohnson1234 MainEau ClaireWI SallyShue7484 MainAltoonaWI MollyMae2342 MainMondoviWI JillJohnson1234 MainEau ClaireWI JoeJohnson9898 GrandeElk MoundWI
How to Correct Multivalued or Repeating Attributes 1.Create new entity 2.New entity could be weak/dependent/identifying 3.New entity could independent
Multivalued Attributes: Table Add rows, not columns PHONE Emp IDPhone NumberType H C H C O F O
Identify & Name the 1NF Violations
Resulting Table STUDENT Student Name AddressEmergency Contact Info Joe Johnson1234 Main, Eau Claire, WI 54703Herbert and Gertrude Johnson, 1234 Main, Eau Claire, WI Sally Shue7484 Main, Altoona, WI 54720Simon and Susan Shue, 7484 Main, Altoona, WI Molly Mae2342 Main, Mondovi, WI 54755Albert and Alfreda Mae, 2342 Main, Mondovi, WI 54755, Jill Johnson1234 Main, Eau Claire, WI 54703Herbert and Gertrude Johnson, 1234 Main, Eau Claire, WI Joe Johnson9898 Grande, Elk Mound, WI 54739Louise Johnson, 9898 Grande, Elk Mound, WI
Identify & Name the 1NF Violations
Resulting Table STUDENT Student_IDFirst NameLast NameStreetCityStateZipEmerg Phone ClassesGradesSports & Activities Position 12345JoeJohnson1234 MainEau ClaireWI Biology, English, Algebra A, B, BFootball, Basketball, Baseball, Choir, Tennis QB, Bass, #1 Doubles 23435SallyShue7484 MainAltoonaWI Biology, English, Algebra B, B, ADebate, Band, Tennis Parliament ary, 1 st Flute, #1 Doubles 23424MollyMae2342 MainMondoviWI Chemistry, Art, Math A, B, A, BSpeechImpromptu 12346JillJohnson1234 MainEau ClaireWI Algebra, English, Art A, A, Chess, Tennis President, #1 Singles 12347JoeJohnson9898 Grande Elk MoundWI Math, Trigonomet ry, Chemistry A, A, AChess,VP, #1 Singles
Is This a Good Solution?
Resulting Table STUDENT Student_ID First Name Last Name Class 1Grade 1Class 2Grade 2Class 3Grade 3Sport/A ctivity 1 PositionSport/A ctivity 2 PositionSport/A ctivity 3 Position 12345JoeJohnsonBiologyAEnglishBAlgebraBFootballQBChoirBassTennis#1 Doubles 23435SallyShueBiologyBEnglishBAlgebraADebateParliam entary Band1 st FluteTennis#1 Doubles 23424MollyMaeChemist ry AArtBMathASpeechImprom ptu 12346JillJohnsonAlgebraAEnglishAArtAChessPreside nt Tennis#1 Single 12347JoeJohnsonMathATrigono metry AChemist ry AChessVP
How would you Solve This Problem? EMPLOYEE Emp_IDFnameLnameDependent1Dependent2Dependent3 1JoeJohnsonJohnnyJane 2MaryZabowskiElizabethMadisonLogan 3JoeyChoAnnie 4EllenMaffeyRobertBlaine What about employees with more than 3 children?
Second Normal Form (2NF) Entities meet 1NF requirements PLUS All attributes are functionally dependent upon the entire primary key.
Identify & Name the 2NF Violations
Resulting Table STUDENT Student_IDFirst NameLast NameClassGradesSport or Activity Position 12345JoeJohnsonBiologyAFootballQB 12345JoeJohnsonEnglishBBasketballGuard 12345JoeJohnsonAlgebraBBaseballCatcher 12345JoeJohnsonChoirBass 12345JoeJohnsonTennis#1 Doubles 23424MollyMaeChemistryASpeechImpromptu 23424MollyMaeArtB 23424MollyMaeMathA
Third Normal Form (3NF) Violation Entities meet 2NF requirements BUT One non-key attribute determines another non- key attribute
Completed 3NF ERD
What are the Values for the Associative Entities?
Resulting Relations STUDENT Student_ID First NameLast NameAdd_IDPhoneGuardian_ID 12345JoeJohnson SallyShue MollyMae JillJohnson JoeJohnson CLASS Class_IDName 10Biology 20English 30Algebra 40Chemistry 50Math 60Art 70Trigonometry 80History 90Geography SPORT/ ACTIVITY Event_IDName 100Football 101Debate 102Speech 103Chess 104Choir 105Band 106Basketball 107Tennis 108Baseball 109Hockey ENROLLMENT Enrollment_IDYearSemesterGradeClass_IDStudent_ID FallB FallF FallA SpringB SpringC SpringB PARTICIPATION PartIDPositionStudent_IDEvent_ID 2222 nd Singles Guard Alto QB Forensics Forensics st Doubles st Doubles ADDRESS Add_IDZipStateCityStreet WIEau Claire1234 Main WIAltoona7484 Main WIMondovi2342 Main WIElk Mound9898 Grande GUARDIAN Guardian_ID First NameLast NameAdd_IDPhone 1HerbertJohnson SimonShue AlbertMae LouiseJohnson
Review Know the difference between 1NF, 2NF and 3NF Ensure your ERD (and resulting database) is in at least 2NF 3NF is the standard (with purposeful violations based on performance)
Application to Your Project Define the necessary tables from every DFD data store Create an ERD to model the data storage Normalize the ERD to 3NF Create mock-up relations to test your model Include the ERD and mock-up relations in your final project documentation
Data Modeling Practice 1.A vendor supplies many products. 2.A product is supplied by many vendors. 3.A customer buys one or more products. 4.Each product can be purchased by many customers. 5.An employee can help many customers. 6.A customer is helped by one or more employees. 7.Each employee works in one department. 8.A department has many employees (working in it). 9.Each department is part of many stores. 10.Each store contains many departments. Scenario: Chain stores (e.g., Target) that contain several departments and sell many products to many customers.