Lecture 02 - Database Concepts LIVE

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

©2022 COMM335 Teaching Team. This content is protected and may not be shared, uploaded, or distributed.

14 Data Normalization

DATABASE CONCEPTS &


DATA NORMALIZATION

COMM 335 Information Systems Technology and Development

Normalization Normalizing a Table to 1NF


15 16

 Normalization is a process used to improve the design of relational NON-Normalized table 1NF: Convert multi-valued columns
databases with multi-valued columns into additional rows with single-
 Within one Table, each Row must be unique (identified by Primary Key) (repeating groups) valued columns and unique PK
 Within each Row, each value in each Column must be single-valued PK = ClientID Composite PK = ClientID, PetNo
 Multiple-values of the content represented by the column (repeating
group) are NOT allowed in any rows of the table
 Normal Form (NF) represents a set of particular conditions (whose purpose
is reducing data redundancy) that a table has to satisfy

Source: Database Systems - Jukić, Vrbsky, Nestorov, Sharma

COMM 335 1
©2022 COMM335 Teaching Team. This content is protected and may not be shared, uploaded, or distributed.

Normalizing a Table to 3NF Example: AD CAMPAIGN MIX Table in 1NF


17 18

1NF: 3NF: Create a new table for each


Table with redundant data repeating group and relate them with FK
Composite PK = ClientID, PetNo Composite PK = ClientID, PetNo

Source: Database Systems - Jukić, Vrbsky, Nestorov, Sharma Source: Database Systems - Jukić, Vrbsky, Nestorov, Sharma

Redundant Data Anomalies


19 20

Source: Database Systems - Jukić, Vrbsky, Nestorov, Sharma Source: Database Systems - Jukić, Vrbsky, Nestorov, Sharma

COMM 335 2
©2022 COMM335 Teaching Team. This content is protected and may not be shared, uploaded, or distributed.

Functional Dependencies 2NF: Removed Partial Dependencies


21 22

Full: Nonkey(s) functionally


FULL DEPENDENCY dependent on a whole Primary Key

TRANSITIVE DEPENDENCY TRANSITIVE DEPENDENCY

Transitive: Nonkey functionally


determines other Nonkey(s) PARTIAL DEPENDENCIES
Partial: Nonkey(s) functionally
dependent on a component of
a composite Primary Key
Source: Database Systems - Jukić, Vrbsky, Nestorov, Sharma Source: Database Systems - Jukić, Vrbsky, Nestorov, Sharma

3NF: Removed Transitive Dependency Example: AD CAMPAIGN Normalized Tables


23 24

FULL DEPENDENCIES

Source: Database Systems - Jukić, Vrbsky, Nestorov, Sharma Source: Database Systems - Jukić, Vrbsky, Nestorov, Sharma

COMM 335 3
©2022 COMM335 Teaching Team. This content is protected and may not be shared, uploaded, or distributed.

Activity: Data Normalization Solution: Anomalies


25 26

1. Identify the existing Anomalies  UPDATE (MODIFY) anomaly:


2. Identify Tables and their Relationships  Updating Students' names, Instructors' names, and Courses' titles takes longer and
can cause inconsistencies because it requires editing many rows.
3. Decompose this dataset into Normalized tables (3NF)  INSERT anomaly:
StuID Student CourseID Course InstID Instructor Year Term Grade  Adding new Students: inserting a new Student cannot be done unless they register in
11 Dana Doe COMM205 Intro to MIS 44 Zorana 2018 1 A a course.
13 Alex Amari COMM437 Database 44 Zorana 2018 2 A+  Adding new Courses: inserting a new Course cannot be done unless the course is
11 Dana Doe COMM335 Info Systems 22 Alym 2019 1 F taught by an instructor and has at least one registered student.
12 Sam Smith COMM335 Info Systems 22 Alym 2019 2 C  Adding new Instructors: inserting a new Instructor cannot be done unless they teach a
14 Blake Brown COMM205 Intro to MIS 33 Sabrina 2020 2 C+ course to at least one student.
11 Dana Doe COMM335 Info Systems 33 Sabrina 2020 2 C  DELETE anomaly:
12 Sam Smith COMM447 Project Mgmt 44 Zorana 2021 1 B+  If a Student drops a Course taught by an Instructor during a registration and they
14 Blake Brown COMM335 Info Systems 44 Zorana 2021 1 B were the only student, next students cannot see the instructor and the course.

Solution: Tables & Relationships Solution: 3NF TABLE (PrimaryKey, ForeignKey, NonKey)
27 28

 Tables: STUDENT (StuID, Student) INSTRUCTOR (InstID, Instructor)


StuID Student InstID Instructor
 Student, Course, Instructor, Grade 11 Dana Doe 22 Alym
12 Sam Smith 33 Sabrina
 Relationships: 13 Alex Amari 44 Zorana
14 Blake Brown
 Each Student can take many Courses, but they cannot take same Course GRADE (StuID, CourseID, InstID, Year, Term, Grade)
more than once in the same Year and Term. StuID CourseID InstID Year Term Grade
COURSE (CourseID, Course) 11 COMM205 44 2018 1 A
 Each Student will earn a Grade for the Course they took in a specific Year CourseID Course 13 COMM437 44 2018 2 A+
and Term. COMM205 Intro to MIS 11 COMM335 22 2019 1 F
COMM335 Info Systems 12 COMM335 22 2019 2 C
 Each Course can be taught by many Instructors, and each Instructor can COMM437 Database 14 COMM205 33 2020 2 C+
teach many Courses. COMM447 Project Mgmt 11 COMM335 33 2020 2 C
12 COMM447 44 2021 1 B+
14 COMM335 44 2021 1 B

COMM 335 4
©2022 COMM335 Teaching Team. This content is protected and may not be shared, uploaded, or distributed.

Solution: 3NF Alternative (GradeID)


29

 Instead of composite primary key (StuID, CourseID, InstID, Year, Term),


add the surrogate primary key (GradeID) for the associative table 30 Breakout: C02-Q
GRADE (GradeID, StuID, CourseID, InstID, Year, Term, Grade)
GradeID StuID CourseID InstID Year Term Grade
1 11 COMM205 44 2018 1 A
2 13 COMM437 44 2018 2 A+
Functional Dependencies
3 11 COMM335 22 2019 1 F
4 12 COMM335 22 2019 2 C
5 14 COMM205 33 2020 2 C+ Submit your answers via Modules > Class 02 > C02-Q
6 11 COMM335 33 2020 2 C
7 12 COMM447 44 2021 1 B+
8 14 COMM335 44 2021 1 B

©2022 COMM 335 Teaching Team


43

This content is protected and may not be shared, uploaded, or distributed.


34 Breakout: C02-EX
This lecture presentation and the slides that accompany it are the
exclusive copyright of COMM 335 teaching team and may only be
Data Normalization Exercise used by students enrolled in COMM 335 course at the University of
British Columbia, Sauder School of Business. Unauthorized or
commercial use of these lectures, including uploading to sites off of
Submit your answers via Modules > Class 02 > C02-EX the University of British Columbia servers, is expressly prohibited!

COMM 335 5

You might also like