Lecture Note 4 - Dependencies and Normalization
Lecture Note 4 - Dependencies and Normalization
Unit 4
Dependencies
And
Normalization
Dilini Thamarasee 1
Content
• Anomalies
– Insertion
– Deletion
– Update
• Dependencies
– Functional
– Partial
– Transitive
• Normalization
– 1st Normal Form
– 2nd Normal Form
– 3rd Normal Form
2
What is Normalization ?
3
Objective of Normalization
4
Benefits of Normalization
5
Pros and Cons of Normalization
Pros:
Cons:
– You can’t start building the database before you know what the user needs.
6
Anomalies
• The inconsistencies occur in the database in attempts to insert, update or delete a
record
• In the previous example, the course relation is not fully inline with relational
concepts
7
Insertion Anomaly
8
Deletion Anomaly
• Suppose the Student S575 wants to withdraw from the course C500;
– If the particular row is deleted, the details of the course C500 will also
be deleted
– As the only student enrolled for C500 is the student S575, deleting
student S575 will cause the loss of Course C500, and therefore will not
have its fee recorded
9
Update Anomaly
• Suppose that the fee of the Course C200 needs to be increased from 75 to 100;
10
Functional Dependencies
• Functional Dependency is a relationship between two attributes
A B
Determinant
ISBN Book_title
B is functionally dependent on A
11
Functional Dependency
• All non key attributes should be fully dependent on the key of the relation
• In a case of a composite key, the whole key will functionally determine the
non key attributes
12
Partial Dependency
13
Example
StudentID CourseID Fee
S120 C200 75
S200 C300 100
S240 C200 75
S425 C400 150
S500 C300 100
S575 C500 50
.. .. ..
.. .. ..
COURSE
Relation/Table
14
Transitive Dependency
• Each non key attribute should be dependent only on the relation’s key; but not on
any other non key attribute.
• Violation of this property implies that the relation combines data from several
entities. This is called transitive dependency
15
Steps in Normalization
Un-normalized Form
DName DNumber DMgrNo DLocations
16
DName DNumber DMgrNo DLocation
Colombo
Research 5 335 Galle
Kandy
Admin 4 987 Moratuwa
HO 1 123 Colombo
17
First Normal Form (INF)
A table is in first normal form if it contains no repeating
groups.
DName DNumber DMgrNo DLocation
Research 5 335 Colombo
Research 5 335 Galle
Research 5 335 Kandy
Admin 4 987 Mortuwa
HO 1 123 Colombo
First normal form also does not allow multi-valued attributes which are composite
and represents a nested relation within the main relation
Projects
ENo Ename
PNo Hours
Un-Normalized
Eno Ename PNo Hours
Form
PNo is the partial key of the nested relation
19
First Normal Form (INF)
• To normalize in to INF
Emp Emp-Proj
20
Second Normal Form (2NF)
A relation is in second normal form (2NF) if and only if it is in 1NF and every
non-key attribute is fully dependent on the primary key.
Emp-Proj
PNo Location
Projects
22
23
Table should have a field that uniquely identifies each of its records, and each field
in the table should describe the subject that the table represents.
24
Third Normal Form (3NF)
• When a relation has more than one candidate key, anomalies may occur, even
though the relation is already in the 3NF
26
Boyce_Codd Normal Form (BCNF)
S2 SE Ins-4
S3 DB Ins-1 Relation is already in 3NF as
S3 OS Ins-5 there are no transitive
dependencies, but not in
S4 DB Ins-6 BCNF
S5 DB Ins-2
27
Boyce_Codd Normal Form (BCNF)
28
Forth Normal Form (4NF)
• When a relation is in BCNF, there may not be any anomalies caused due to
functional dependencies
29
Forth Normal Form (4NF)
• Same textbook will be used by may instructors, and one instructor may refer
several textbooks
30
Forth Normal Form (4NF)
31
Forth Normal Form (4NF)
Course Instructor
Management White
Management Green
Management Black Course Textbook
Finance Gray Management Drucker
Management Peters
Finance Weston
Finance Gilford
33
Fifth Normal Form (5NF)
• Join Dependency:
• Relation cannot be divided into two relations
• And then the resulting relations cannot be recombined to form the original
relation
34
35