Chapter 3 Relational Data Model and Normalization
Chapter 3 Relational Data Model and Normalization
CSI300
RELATIONAL DATA MODEL AND NORMALIZATION AUCE
1
DEFINITIONS
• Informally, a relation looks like a table of values (see Figure on
next slide).
Entity
Relation :
Relationship
RELATIONAL DATABASE STATE
• Next two slides show an example of a COMPANY database state
– Each relation has a set of tuples
• The tuples in each table satisfy key and other constraints
• If all constraints are satisfied by a database state, it is called a valid state
– The database state changes to another state whenever the tuples
in any relation are changed via insertions, deletions, or updates
Continued next slide…
ANOMALIES IN DBMS
18
ANOMALIES IN DBMS
Insert anomaly : Suppose a new employee joins the company, who is under
training and currently not assigned to any department then we would not be able to
insert the data into the table if emp_dept field doesn’t allow nulls.
20
FIRST NORMAL FORM (1NF)
The official qualifications for 1NF are:
1. Each attribute name must be unique.
2. Each attribute value must be single.
3. Each row must be unique.
4. There is no repeating groups.
Additional:
Choose a primary key.
Reminder:
A primary key is unique, not null, unchanged. A primary
key can be either an attribute or combined attributes. 21
FIRST NORMAL FORM (1NF)
22
FIRST NORMAL FORM (1NF)
23
FUNCTIONAL DEPENDENCIES
24
FUNCTIONAL DEPENDENCIES
25
FUNCTIONAL DEPENDENCIES
26
DETERMINANT
27
SECOND NORMAL FORM (2NF)
28
SECOND NORMAL FORM (2NF)
27
29
SECOND NORMAL FORM (2NF)
27
30
THIRD NORMAL FORM (3NF)
31
32
1
33
BOYCE CODD NORMAL FORM (BCNF) – 3.5NF
34
SUPER KEY
A superkey is a combination of columns that uniquely identifies any row within
a relational database management system (RDBMS) table.
A candidate key is a closely related concept where the superkey is reduced to
the minimum number of columns required to uniquely identify each row.
35
BOYCE CODD NORMAL FORM (BCNF) – 3.5NF
36
37
Example: Suppose a school wants to store the data of teachers and the subjects they
teach. They create a table that looks like this: Since a teacher can teach more than
one subjects, the table can have multiple rows for a same teacher.
The table is in 1 NF because each attribute has atomic values. However, it is not in
2NF because non prime attribute teacher_age is dependent on teacher_id alone
which is a proper subset of candidate key (partial dependency). This violates the rule
for 2NF as the rule says “no non-prime attribute is dependent on a part of primary
key of the table”. 38
To make the table complies with 2NF we can break it in two tables like this:
teacher_details table:
Now the tables comply with third normal form (3NF) also. 39
Example: Suppose a company wants to store the complete address of each
employee, they create a table named employee_details that looks like this:
employee_zip table:
41