Database Normalization
Database Normalization
Normalization
Purpose of Normalization
• Normalization is a technique for producing a
set of suitable relations that support the data
requirements of an enterprise.
2
Purpose of Normalization
• Characteristics of a suitable set of relations
include:
– the minimal number of attributes necessary to
support the data requirements of the enterprise;
– attributes with a close logical relationship are
found in the same relation;
– minimal redundancy with each attribute
represented only once with the important
exception of attributes that form all or part of
foreign keys.
3
Purpose of Normalization
• The benefits of using a database that has a
suitable set of relations is that the database
will be:
– easier for the user to access and maintain the
data;
– take up minimal storage space on the computer.
4
How Normalization Supports Database Design
5
Data Redundancy and Update Anomalies
• Major aim of relational database design is to
group attributes into relations to minimize data
redundancy.
6
Data Redundancy and Update Anomalies
• Potential benefits for implemented database
include:
– Updates to the data stored in the database are
achieved with a minimal number of operations
thus reducing the opportunities for data
inconsistencies.
– Reduction in the file storage space required by the
base relations thus minimizing costs.
7
Data Redundancy and Update Anomalies
• Problems associated with data redundancy are
illustrated by comparing the Staff and Branch
relations with the StaffBranch relation.
8
Data Redundancy and Update Anomalies
9
Data Redundancy and Update Anomalies
• StaffBranch relation has redundant data; the
details of a branch are repeated for every
member of staff.
• In contrast, the branch information appears only
once for each branch in the Branch relation and
only the branch number (branchNo) is repeated
in the Staff relation, to represent where each
member of staff is located.
10
Data Redundancy and Update Anomalies
• Relations that contain redundant information
may potentially suffer from update anomalies.
11
Lossless-join and Dependency Preservation
Properties
• Two important properties of decomposition.
– Lossless-join property enables us to find any
instance of the original relation from
corresponding instances in the smaller relations.
– Dependency preservation property enables us to
enforce a constraint on the original relation by
enforcing some constraint on each of the smaller
relations.
12
Functional Dependencies
• Important concept associated with
normalization.
• Functional dependency describes relationship
between attributes.
• For example, if A and B are attributes of relation
R, B is functionally dependent on A (denoted A
B), if each value of A in R is associated with
exactly one value of B in R.
13
Characteristics of Functional Dependencies
• Property of the meaning or semantics of the
attributes in a relation.
• Diagrammatic representation.
15
Example Functional Dependency that holds
for all Time
• Consider the values shown in staffNo and sName
attributes of the Staff relation (see Slide 9).
• Based on sample data, the following functional
dependencies appear to hold.
staffNo → sName
sName → staffNo
16
Example Functional Dependency that holds
for all Time
• However, the only functional dependency that
remains true for all possible values for the
staffNo and sName attributes of the Staff
relation is:
staffNo → sName
17
Characteristics of Functional Dependencies
• Determinants should have the minimal number
of attributes necessary to maintain the
functional dependency with the attribute(s) on
the right hand-side.
18
Characteristics of Functional Dependencies
• Full functional dependency indicates that if A
and B are attributes of a relation, B is fully
functionally dependent on A, if B is functionally
dependent on A, but not on any proper subset of
A.
19
Example Full Functional Dependency
• Exists in the Staff relation
staffNo, sName → branchNo
22
Example Transitive Dependency
• Consider functional dependencies in the
StaffBranch relation (see Slide 12).
24
Identifying Functional Dependencies
• Identifying all functional dependencies between
a set of attributes is relatively simple if the
meaning of each attribute and the relationships
between the attributes are well understood.
25
Identifying Functional Dependencies
• However, if the users are unavailable for
consultation and/or the documentation is
incomplete then depending on the database
application it may be necessary for the database
designer to use their common sense and/or
experience to provide the missing information.
26
Example - Identifying a set of functional dependencies
for the StaffBranch relation
• Examine semantics of attributes in StaffBranch
relation (see Slide 12). Assume that position held
and branch determine a member of staff’s salary.
27
Example - Identifying a set of functional dependencies
for the StaffBranch relation
• With sufficient information available, identify
the functional dependencies for the StaffBranch
relation as:
staffNo → sName, position, salary, branchNo,
bAddress
branchNo → bAddress
bAddress → branchNo
branchNo, position → salary
bAddress, position → salary
28
Example - Using sample data to identify
functional dependencies.
• Consider the data for attributes denoted A, B, C,
D, and E in the Sample relation (see Slide 33).
29
Example - Using sample data to identify
functional dependencies.
30
Example - Using sample data to identify
functional dependencies.
• Function dependencies between attributes A to
E in the Sample relation.
AC (fd1)
CA (fd2)
B D (fd3)
A, B E (fd4)
31
Identifying the Primary Key for a Relation using
Functional Dependencies
• Main purpose of identifying a set of functional
dependencies for a relation is to specify the set
of integrity constraints that must hold on a
relation.
32
Example - Identify Primary Key for StaffBranch
Relation
• StaffBranch relation has five functional
dependencies
• The determinants are staffNo, branchNo,
bAddress, (branchNo, position), and (bAddress,
position).
34
Example - Identifying Primary Key for Sample
Relation
• Sample relation has four functional dependencies
• The determinants in the Sample relation are A, B, C,
and (A, B). However, the only determinant that
functionally determines all the other attributes of the
relation is (A, B).
35
The Process of Normalization
• As normalization proceeds, the relations
become progressively more restricted (stronger)
in format and also less vulnerable to update
anomalies.
36
The Process of Normalization
37
The Process of Normalization
38
Unnormalized Form (UNF)
• A table that contains one or more repeating
groups.
39
First Normal Form (1NF)
• A relation in which the intersection of each
row and column contains one and only one
value.
40
UNF to 1NF
• Nominate an attribute or group of attributes
to act as the key for the unnormalized table.
41
UNF to 1NF
• Remove the repeating group by
– Entering appropriate data into the empty
columns of rows containing the repeating data
(‘flattening’ the table).
– Or by
– Placing the repeating data along with a copy of
the original key attribute(s) into a separate
relation.
42
Second Normal Form (2NF)
• Based on the concept of full functional
dependency.
43
Second Normal Form (2NF)
• A relation that is in 1NF and every non-
primary-key attribute is fully functionally
dependent on the primary key.
44
1NF to 2NF
• Identify the primary key for the 1NF relation.
47
2NF to 3NF
• Identify the primary key in the 2NF relation.
48
General Definitions of 2NF and 3NF
• Second normal form (2NF)
– A relation that is in first normal form and every
non-primary-key attribute is fully functionally
dependent on any candidate key.
49