CCT395, Week 5 Translating ER into Relations; Normalization This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from Yuri Takhteyev University of Toronto October 6, 2010
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
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
course code title session code start date room code capacity building code map url student last name first name
course code title session code start date student last name first name room code capacity building code map url
course code title session code start date student last name first name room code capacity building code map url enrol lmen t
course code title session code start date student last name first name room code capacity building code map url enrol lmen t
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
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
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
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
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
course code title session code start date student last name first name room code capacity building code map url enrollment course instance final exam?
course code title session code start date student last name first name room code capacity building code map url enrollment course instance final exam?
Step 1 “Create one table for each entity” (after breaking up M:M)
student last name first name student
last name first name student
last name first name student
last name first name student
(do this for every entity)
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.”
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.”
course code title session code start date student last name first name room code capacity building code map url enrollment course instance final exam?
course code title session code start date student last name first name room code capacity building code map url enrollment course instance final exam?
course code title session code start date student last name first name room code capacity building code map url enrollment course instance final exam?
course code title session code start date student last name first name room code capacity building code map url enrollment course instance final exam?
course code title session code start date student last name first name room code capacity building code map url enrollment course instance final exam?
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.”
Keys no key! student
Keys a candidate key student
Keys another candidate key student
Keys candidate #1 student candidate #2
Keys candidate #1 student candidate #2 candidate #1 primary key
Multi-Column Keys city a key!
Multi-Column Keys city a three column key
Multi-Column Keys city candidate #1 candidate #2
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.”
student
let’s add it student
course code title session code start date student last name first name room code capacity building code map url enrollment course instance final exam?
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?
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?
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.”
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.”
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?
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?
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.”
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?
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?
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?
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
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
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.”
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
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.”
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
Step 4c If necessary, add a field!
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
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
Step 4d Go back to step 3!
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
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*
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*
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*
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*
course_instance
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*
course_instance
Step 5 Normalize!
Normalization Checking that the table does not have any well-known problems
What Problems?
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
1NF No multi-valued attributes
The Wrong Solution
The Right Solution
2NF and 3NF Getting rid of “functional dependencies”
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!”
course title grade code student id course id student name “Each attribute must describe the key... grade points
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!”
2NF: no partial dependencies (“the whole key”) 3NF: 2NF + no transitive dependencies (“nothing but the key”) 2NF and 3NF
Reaching 2NF and 3NF Decomposition (break up tables into several)
course title grade code student id course id student name grade points
course course title grade code student id course id student name course id student id grade points
course course title grade code student id course id student name grade points grade code course id student id
“all determinants must be candidate keys” BCNF
course time slot instructor id room id course code overlapping candidate keys
course time slot instructor id room id dependencies between keys
course time slot instructor id room id dependencies between keys
course time slot instructor id instructor utorid this is 3NF, but not BCNF (“so help me Codd”)
course time slot instructor id instructor utorid decompose it instructor id
course course id project id student id some relations cannot be decomposed into BCNF (“so help me Codd”) student, course → project project → course
Mistaking binary relationships for ternary 4NF
course code title session code start date room code capacity
course code title session code start date room code capacity cours e insta nce
student job course
5NF “We could break it up yet more”
Questions?