Employee - Open Eau Claire

advertisement
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_ID
12345
First Name
Joe
Last Name
Johnson
Street
1234 Main
City
Eau Claire
State
WI
Zip
54703
Phone
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 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 ID
10
10
14
14
14
14
16
Phone Number
715-123-1234
715-123-4567
715-123-1234
715-123-6789
715-123-1111
715-123-2222
715-123-4545
Type
H
C
H
C
O
F
O
Identify & Name the 1NF Violations
Resulting Table
STUDENT
Student Name
Joe Johnson
Sally Shue
Molly Mae
Jill Johnson
Joe Johnson
Address
1234 Main, Eau Claire, WI 54703
Emergency Contact Info
Herbert and Gertrude Johnson, 1234
Main, Eau Claire, WI 54703 715-1231234
7484 Main, Altoona, WI 54720
Simon and Susan Shue, 7484 Main,
Altoona, WI 54720 715-333-2111
2342 Main, Mondovi, WI 54755
Albert and Alfreda Mae, 2342 Main,
Mondovi, WI 54755, 715-324-7878
1234 Main, Eau Claire, WI 54703
Herbert and Gertrude Johnson, 1234
Main, Eau Claire, WI 54703 715-1231234
9898 Grande, Elk Mound, WI 54739 Louise Johnson, 9898 Grande, Elk
Mound, WI 54739 715-999-8888
Identify & Name the 1NF Violations
Resulting Table
STUDENT
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-1231234
Biology,
English,
Algebra
A, B, B
Football,
Basketball,
Baseball,
Choir,
Tennis
QB, Bass,
#1 Doubles
23435
Sally
Shue
7484 Main
Altoona
WI
54720
715-3332111
Biology,
English,
Algebra
B, B, A
Debate,
Band,
Tennis
Parliament
ary, 1st
Flute, #1
Doubles
23424
Molly
Mae
2342 Main
Mondovi
WI
54755
715-3247878
Chemistry,
Art, Math
A, B, A, B
Speech
Impromptu
12346
Jill
Johnson
1234 Main
Eau Claire
WI
54703
715-1231234
Algebra,
A, A, A, A,
English, Art
Chess,
Tennis
President,
#1 Singles
12347
Joe
Johnson
9898
Grande
Elk Mound
WI
54739
715-9998888
Math,
A, A, A
Trigonomet
ry,
Chemistry
Chess,
VP, #1
Singles
Is This a Good Solution?
Resulting Table
STUDENT
Last
Name
Johnson
Class 1
Grade 1
Class 2
Grade 2
Class 3
Grade 3
12345
First
Name
Joe
Biology
A
English
B
Algebra
23435
Sally
Shue
Biology
B
English
B
23424
Molly
Mae
A
Art
12346
Jill
Johnson
Chemist
ry
Algebra
A
12347
Joe
Johnson
Math
A
Student_ID
Position
B
Sport/A
ctivity 1
Football
Algebra
A
Debate
B
Math
A
Speech
English
A
Art
A
Chess
Trigono
metry
A
Chemist
ry
A
Chess
Parliam
entary
Improm
ptu
Preside
nt
VP
QB
Sport/A
ctivity 2
Choir
Position
Bass
Sport/A
ctivity 3
Tennis
Band
1st Flute
Tennis
Tennis
#1
Single
Position
#1
Doubles
#1
Doubles
How would you Solve This Problem?
EMPLOYEE
Emp_ID
Fname
Lname
Dependent1
Dependent2
1
Joe
Johnson
Johnny
Jane
2
Mary
Zabowski Elizabeth
3
Joey
Cho
Annie
4
Ellen
Maffey
Robert
Madison
Blaine
What about employees with more than 3 children?
Dependent3
Logan
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_ID
First Name
Last Name Class
12345
12345
12345
12345
12345
23424
23424
23424
Joe
Joe
Joe
Joe
Joe
Molly
Molly
Molly
Johnson
Johnson
Johnson
Johnson
Johnson
Mae
Mae
Mae
Biology
English
Algebra
Chemistry
Art
Math
Grades Sport or
Activity
A
Football
B
Basketball
B
Baseball
Choir
Tennis
A
Speech
B
A
Position
QB
Guard
Catcher
Bass
#1 Doubles
Impromptu
Third Normal Form (3NF) Violation
• Entities meet 2NF requirements BUT
• One non-key attribute determines another nonkey attribute
Completed
3NF ERD
What are the Values for the Associative
Entities?
Resulting
Relations
GUARDIAN
Guardian_ID
1
2
3
4
First Name
Herbert
Simon
Albert
Louise
Last Name
Johnson
Shue
Mae
Johnson
Add_ID
1
2
3
1
Phone
715-123-1234
715-333-2111
715-324-7878
715-999-8888
STUDENT
Student_ID
12345
23435
23424
12346
12347
ENROLLMENT
Enrollment_ID
11111
11112
11113
11114
11115
11115
First Name
Joe
Sally
Molly
Jill
Joe
Year
2007
2007
2007
2008
2008
20008
PARTICIPATION
PartID Position
222
2nd Singles
223
Guard
224
Alto
225
QB
226
Forensics
227
Forensics
228
1st Doubles
229
1st Doubles
Student_ID
23424
12346
12346
12345
12346
12345
23435
23424
Last Name
Johnson
Shue
Mae
Johnson
Johnson
Semester
Fall
Fall
Fall
Spring
Spring
Spring
Event_ID
107
106
104
100
101
101
107
107
Add_ID
1
2
3
1
4
Grade
BF
A
B+
C
B
SPORT/
ACTIVITY
Event_ID
100
101
102
103
104
105
106
107
108
109
Phone
715-123-1234
715-333-2111
715-324-7878
715-123-1234
715-999-8888
Class_ID
30
30
60
80
30
90
Name
Football
Debate
Speech
Chess
Choir
Band
Basketball
Tennis
Baseball
Hockey
Guardian_ID
1
2
3
1
4
CLASS
Class_ID
10
20
30
40
50
60
70
80
90
Student_ID
23424
12346
12346
12345
12346
12345
ADDRESS
Add_ID
1
2
3
4
Zip
54703
54720
54755
54739
State
WI
WI
WI
WI
Name
Biology
English
Algebra
Chemistry
Math
Art
Trigonometry
History
Geography
City
Eau Claire
Altoona
Mondovi
Elk Mound
Street
1234 Main
7484 Main
2342 Main
9898 Grande
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.
2.
A vendor supplies many products.
A product is supplied by many vendors.
3.
4.
A customer buys one or more products.
Each product can be purchased by many customers.
5.
6.
An employee can help many customers.
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.
Download