Post on 22-Feb-2016
description
transcript
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 ModelIS 310Dr. 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
STUDENTStudent_ID First Name Last Name Street City State Zip Phone12345 Joe Johnson 1234 Main Eau Claire WI 54703 715-123-1234
23435 Sally Shue 7484 Main Altoona WI 54720 715-333-2111
23424 Molly Mae 2342 Main Mondovi WI 54755 715-324-7878
12346 Jill Johnson 1234 Main Eau Claire WI 54703 715-123-1234
12347 Joe Johnson 9898 Grande Elk Mound WI 54739 715-999-8888
How to Correct Multivalued or Repeating Attributes1. Create new entity2. New entity could be
weak/dependent/identifying3. New entity could independent
Multivalued Attributes: Table•Add rows, not columnsPHONEEmp ID Phone Number Type10 715-123-1234 H10 715-123-4567 C14 715-123-1234 H14 715-123-6789 C14 715-123-1111 O14 715-123-2222 F16 715-123-4545 O
Identify & Name the 1NF Violations
Resulting Table
STUDENTStudent Name Address Emergency Contact InfoJoe Johnson 1234 Main, Eau Claire, WI 54703 Herbert and Gertrude Johnson, 1234
Main, Eau Claire, WI 54703 715-123-1234
Sally Shue 7484 Main, Altoona, WI 54720 Simon and Susan Shue, 7484 Main, Altoona, WI 54720 715-333-2111
Molly Mae 2342 Main, Mondovi, WI 54755 Albert and Alfreda Mae, 2342 Main, Mondovi, WI 54755, 715-324-7878
Jill Johnson 1234 Main, Eau Claire, WI 54703 Herbert and Gertrude Johnson, 1234 Main, Eau Claire, WI 54703 715-123-1234
Joe Johnson 9898 Grande, Elk Mound, WI 54739 Louise Johnson, 9898 Grande, Elk Mound, WI 54739 715-999-8888
Identify & Name the 1NF Violations
Resulting TableSTUDENT
Student_ID First Name Last Name Street City State Zip Emerg Phone
Classes Grades Sports & Activities
Position
12345 Joe Johnson 1234 Main Eau Claire WI 54703 715-123-1234
Biology, English, Algebra
A, B, B Football, Basketball, Baseball, Choir, Tennis
QB, Bass, #1 Doubles
23435 Sally Shue 7484 Main Altoona WI 54720 715-333-2111
Biology, English, Algebra
B, B, A Debate, Band, Tennis
Parliamentary, 1st Flute, #1 Doubles
23424 Molly Mae 2342 Main Mondovi WI 54755 715-324-7878
Chemistry, Art, Math
A, B, A, B Speech Impromptu
12346 Jill Johnson 1234 Main Eau Claire WI 54703 715-123-1234
Algebra, English, Art
A, A, A, A, Chess, Tennis
President, #1 Singles
12347 Joe Johnson 9898 Grande
Elk Mound WI 54739 715-999-8888
Math, Trigonometry, Chemistry
A, A, A Chess, VP, #1 Singles
Is This a Good Solution?
Resulting TableSTUDENTStudent_ID First
NameLast Name
Class 1 Grade 1 Class 2 Grade 2 Class 3 Grade 3 Sport/Activity 1
Position Sport/Activity 2
Position Sport/Activity 3
Position
12345 Joe Johnson Biology A English B Algebra B Football QB Choir Bass Tennis #1 Doubles
23435 Sally Shue Biology B English B Algebra A Debate Parliamentary
Band 1st Flute Tennis #1 Doubles
23424 Molly Mae Chemistry
A Art B Math A Speech Impromptu
12346 Jill Johnson Algebra A English A Art A Chess President
Tennis #1 Single
12347 Joe Johnson Math A Trigonometry
A Chemistry
A Chess VP
How would you Solve This Problem?EMPLOYEEEmp_ID Fnam
eLname Dependent
1Dependent2
Dependent3
1 Joe Johnson Johnny Jane2 Mary Zabows
kiElizabeth Madison Logan
3 Joey Cho Annie4 Ellen Maffey Robert Blaine
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 TableSTUDENTStudent_ID First Name Last Name Class Grades Sport or
ActivityPosition
12345 Joe Johnson Biology A Football QB12345 Joe Johnson English B Basketball Guard12345 Joe Johnson Algebra B Baseball Catcher12345 Joe Johnson Choir Bass12345 Joe Johnson Tennis #1 Doubles23424 Molly Mae Chemistry A Speech Impromptu23424 Molly Mae Art B23424 Molly Mae Math A
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
STUDENTStudent_ID First Name Last Name Add_ID Phone Guardian_ID12345 Joe Johnson 1 715-123-1234 123435 Sally Shue 2 715-333-2111 223424 Molly Mae 3 715-324-7878 312346 Jill Johnson 1 715-123-1234 112347 Joe Johnson 4 715-999-8888 4
CLASSClass_ID Name10 Biology20 English30 Algebra40 Chemistry50 Math60 Art70 Trigonometry80 History90 GeographySPORT/
ACTIVITYEvent_ID Name100 Football 101 Debate 102 Speech103 Chess104 Choir105 Band106 Basketball107 Tennis108 Baseball109 Hockey
ENROLLMENTEnrollment_ID Year Semester Grade Class_ID Student_ID11111 2007 Fall B- 30 2342411112 2007 Fall F 30 1234611113 2007 Fall A 60 1234611114 2008 Spring B+ 80 1234511115 2008 Spring C 30 1234611115 20008 Spring B 90 12345
PARTICIPATIONPartID Position Student_ID Event_ID222 2nd Singles 23424 107223 Guard 12346 106224 Alto 12346 104225 QB 12345 100226 Forensics 12346 101227 Forensics 12345 101228 1st Doubles 23435 107229 1st Doubles 23424 107
ADDRESSAdd_ID Zip State City Street1 54703 WI Eau Claire 1234 Main2 54720 WI Altoona 7484 Main3 54755 WI Mondovi 2342 Main4 54739 WI Elk Mound 9898 Grande
GUARDIANGuardian_ID First Name Last Name Add_ID Phone1 Herbert Johnson 1 715-123-12342 Simon Shue 2 715-333-21113 Albert Mae 3 715-324-78784 Louise Johnson 1 715-999-8888
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 Practice1. 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.