Download presentation
Presentation is loading. Please wait.
Published byLaurel Parker Modified over 8 years ago
1
CCT395, Week 5 Translating ER into Relations; Normalization This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/. This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from http://everaldo.com/crystal/. Yuri Takhteyev University of Toronto October 6, 2010
2
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url probably redundan t might be redundan t
3
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url student enrolls in course course is offered in session course meets in room room is in building
4
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url student ---------------------------------------------- -- last name first name
5
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url
6
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrol lmen t
7
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrol lmen t
8
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce
9
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce
10
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce
11
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce
12
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce
13
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
14
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
15
Step 1 “Create one table for each entity” (after breaking up M:M)
16
student ------------------------------------------------ last name first name student
17
------------------------------------------------ last name first name student
18
------------------------------------------------ last name first name student
19
------------------------------------------------ last name first name student
20
(do this for every entity)
21
Step 2 “For each entity that is only on the ‘one’ end of one or more relationships and not at the ‘many’ end of any relationship, create a single-column primary key... if no natural primary key is available.”
22
Step 2 “For each entity that is only on the ‘one’ end of one or more relationships and not at the ‘many’ end of any relationship, create a single-column primary key... if no natural primary key is available.”
23
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
24
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
25
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
26
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
27
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
28
Step 2 “For each entity that is only on the ‘one’ end of one or more relationships and not at the ‘many’ end of any relationship, create a single-column primary key... if no natural primary key is available.”
29
Keys no key! student
30
Keys a candidate key student
31
Keys another candidate key student
32
Keys candidate #1 student candidate #2
33
Keys candidate #1 student candidate #2 candidate #1 primary key
34
Multi-Column Keys city a key!
35
Multi-Column Keys city a three column key
36
Multi-Column Keys city candidate #1 candidate #2
37
Step 2 “For each entity that is only on the ‘one’ end of one or more relationships and not at the ‘many’ end of any relationship, create a single-column primary key... if no natural primary key is available.”
38
student
39
let’s add it student
41
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
42
course ---------------------------------------------- -- code* title session ---------------------------------------------- -- code* start date student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code* map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
43
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
44
Step 3 “For each entity that is at the ‘many’ end of one or more relationships, include the primary key of each parent entity in the table as foreign keys.”
45
Step 3 “For each entity that is at the ‘many’ end of one or more relationships, include the primary key of each parent entity in the table as foreign keys.”
46
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
47
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
48
Step 3 “For each entity that is at the ‘many’ end of one or more relationships, include the primary key of each parent entity in the table as foreign keys.”
49
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
50
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
51
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?
52
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id course instance ---------------------------------------------- -- final exam? course_id session_id
53
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id course instance ---------------------------------------------- -- final exam? course_id session_id
54
Step 4a “If an entity at the ‘many’ end of one or more relationships, has a natural primary key, use that single key as a the primary key.”
55
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id course instance ---------------------------------------------- -- final exam? course_id session_id
56
Step 4b “Otherwise, concatenate the primary key of its parent with any other column or columns needed for uniqueness to form the table’s primary key.”
57
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id course instance ---------------------------------------------- -- final exam? course_id session_id
58
Step 4c If necessary, add a field!
59
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id room_id* building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id course instance ---------------------------------------------- -- final exam? course_id session_id
60
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id room_id* building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id course instance ---------------------------------------------- -- final exam? course_id session_id
61
Step 4d Go back to step 3!
62
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id room_id* building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id course instance ---------------------------------------------- -- final exam? course_id session_id room_id
63
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id room_id* building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id course instance ---------------------------------------------- -- final exam? course_id* session_id* room_id*
64
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id room_id* building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id course instance ---------------------------------------------- -- final exam? course_id* session_id* room_id*
65
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id room_id* building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id* instance_id * course instance ---------------------------------------------- -- final exam? course_id session_id room_id instance_id*
66
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id room_id* building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id* instance_id* course instance ---------------------------------------------- -- final exam? course_id session_id room_id instance_id*
67
course_instance
68
course ---------------------------------------------- -- code title course_id* session ---------------------------------------------- -- code start date session_id* student ---------------------------------------------- -- last name first name student_id* room ---------------------------------------------- -- code capacity building_id room_id* building ---------------------------------------------- -- code map url building_id* enrollment ---------------------------------------------- -- student_id* instance_id* course instance ---------------------------------------------- -- final exam? course_id session_id room_id instance_id*
69
course_instance
70
Step 5 Normalize!
71
Normalization Checking that the table does not have any well-known problems
72
What Problems?
73
Normal Forms 4 th Normal Form BC Normal Form 3 rd Normal Form 2 nd Normal Form 1 st Normal Form 5 th Normal Form trivial! you can do it! fixing weird issues
74
1NF No multi-valued attributes
76
The Wrong Solution
77
The Right Solution
78
2NF and 3NF Getting rid of “functional dependencies”
79
course title grade code student id course id student name “Each attribute must describe the key, grade points the whole key, and nothing but the key.” “So help me Codd!”
80
course title grade code student id course id student name “Each attribute must describe the key... grade points
81
course title grade code student id course id student name “Each attribute must describe the key, the whole key, and nothing but the key.” grade points partial dependency full dependency transitive dependency “So help me Codd!”
82
2NF: no partial dependencies (“the whole key”) 3NF: 2NF + no transitive dependencies (“nothing but the key”) 2NF and 3NF
83
Reaching 2NF and 3NF Decomposition (break up tables into several)
84
course title grade code student id course id student name grade points
85
course course title grade code student id course id student name course id student id grade points
86
course course title grade code student id course id student name grade points grade code course id student id
87
“all determinants must be candidate keys” BCNF
88
course time slot instructor id room id course code overlapping candidate keys
89
course time slot instructor id room id dependencies between keys
90
course time slot instructor id room id dependencies between keys
91
course time slot instructor id instructor utorid this is 3NF, but not BCNF (“so help me Codd”)
92
course time slot instructor id instructor utorid decompose it instructor id
93
course course id project id student id some relations cannot be decomposed into BCNF (“so help me Codd”) student, course → project project → course
94
Mistaking binary relationships for ternary 4NF
95
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date room ---------------------------------------------- -- code capacity
96
course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date room ---------------------------------------------- -- code capacity cours e insta nce
97
student ---------------------------------------------- -- job ------------------------------------------------ course ------------------------------------------------
98
5NF “We could break it up yet more”
99
Questions?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.