0% found this document useful (0 votes)
33 views35 pages

Lecture Note 4 - Dependencies and Normalization

The document discusses database normalization including anomalies, dependencies, and normal forms. It defines insertion, deletion, and update anomalies and describes functional, partial, and transitive dependencies. It also explains 1st, 2nd, 3rd normal forms and Boyce-Codd normal form and the benefits of normalization.

Uploaded by

Android TV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views35 pages

Lecture Note 4 - Dependencies and Normalization

The document discusses database normalization including anomalies, dependencies, and normal forms. It defines insertion, deletion, and update anomalies and describes functional, partial, and transitive dependencies. It also explains 1st, 2nd, 3rd normal forms and Boyce-Codd normal form and the benefits of normalization.

Uploaded by

Android TV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Database and Data structures I

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 ?

• A design technique that is widely used as a guide in designing relational databases

• Two step process that puts data in a tabular form


– removes repeating groups
– then removes duplicated data from the relational tables

• Based on the concepts of normal forms

• Relation should satisfy a set of constraints to be in a normal form

3
Objective of Normalization

• Eliminate redundant fields.

• Avoid merging tables.

4
Benefits of Normalization

• Elimination of redundant data storage.

• Close modeling of real world entities, processes, and their relationships.

• Structuring of data so that the model is flexible.

• Allows users to insert, delete or modify rows in relations without causing


errors or inconsistencies

5
Pros and Cons of Normalization
Pros:

– More efficient database structure.

– Better understanding of your data.

– More flexible database structure.

– Easier to maintain database structure.

– Avoid redundant fields.

– Insure that distinct tables exist when necessary.

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

• This happens due to


• Data redundancy
• Transitive dependency of relations

• In the previous example, the course relation is not fully inline with relational
concepts

7
Insertion Anomaly

• suppose a new course(C600) needs to be added to the Course table;


– It cannot be added until at least on student is enrolled to the
course
– Each row of the relation must contain a Student ID

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;

– Modifications should be applied to all the rows where the course


ID is C200.

– Otherwise, the data will be inconsistent

10
Functional Dependencies
• Functional Dependency is a relationship between two attributes

– Attribute B is functionally dependent on attribute A if at a given time the value of A


determine the value of B

A B

Determinant

ISBN Book_title

B is functionally dependent on A
11
Functional Dependency

• A property of the meaning (semantics) of attribute

• Dependency is specified as a constraint

• 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

• Some attributes depend on part of the primary key

• If we have composite key, some attributes depend on part of composite


key.

StuID CourseID Hours

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

• A relation which is transitive dependent, should be further decomposed in to


relations

15
Steps in Normalization

Un-normalized Form
DName DNumber DMgrNo DLocations

DName DNumber DMgrNo DLocations


{Colombo, Galle,
Research 5 335
Kandy}
Admin 4 987 {Moratuwa}
HO 1 123 {Colombo}

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

INF Version with Redundancy


18
First Normal Form (INF)

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

– Remove the nested relation attributes to a new relation

– Propagate the primary key of the original table into new


relation

ENo EName ENo PNo Hours

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.

• Any partial functional dependency needs to be removed

• your table is in 2NF if:

– It doesn’t have any repeating groups

– Each of the fields that isn’t a part of the key is


functionally dependent on the entire key.

If a single-field key is used, a 1NF table is already in 2NF. 21


ENo EName
Emp

ENo PNo Hours

Emp-Proj

PNo Location

Projects

22
23

Second Normal Form (2NF)

ENo PNo Hours EName PName Location


FD1
FD2
FD3

ENo PNo Hours

In 2NF ENo EName

PNo PName Location


Third Normal Form (3NF)

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.

• Any transitive dependencies should be removed

• Performs an additional level of verification that you have not


combined tables.

24
Third Normal Form (3NF)

ENo EName DOB Address DNo DName DMgrNo

ENo EName DOB Address DNo


3NF

DNo DName DMgrNo


Boyce_Codd Normal Form (BCNF)

• Further enhancement in 3NF

• When a relation has more than one candidate key, anomalies may occur, even
though the relation is already in the 3NF

• Any remaining anomaly, which result from functional dependency will be


removed

26
Boyce_Codd Normal Form (BCNF)

Student Course Instructor


S1 DB Ins-1
S2 DB Ins-2 FD1: {Student,Course} → Instructor

S2 OS Ins-3 FD2: Instructor → Course

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)

• In this relation, no single attribute is a candidate key

• Can be decomposed in to following pairs


• {Student,Instructor} and {Student, Course}
• {Course, Instructor} and {Course, Student}
• {Instructor, Course} and {Instructor, Student}

Instructor Course Instructor Student

28
Forth Normal Form (4NF)

• When a relation is in BCNF, there may not be any anomalies caused due to
functional dependencies

• But, there may still be anomalies caused due to multi-valued dependencies

• Any multi-valued dependency may be removed to make a relation to 4NF

29
Forth Normal Form (4NF)

• Each course may have several instructors

• Each course uses several textbooks

• Same textbook will be used by may instructors, and one instructor may refer
several textbooks

30
Forth Normal Form (4NF)

Course Instructor Textbook


Management White Drucker
Management Green Drucker
Management Black Drucker
Management White Peters Relation with
Multi-valued
Management Green Peters
dependency
Management Black Peters
Finance Gray Weston
Finance Gray Gilford

31
Forth Normal Form (4NF)

• To remove multi-valued dependency, decompose the relation into two


independent attributes

• Relation is in 4NF, if its in BCNF and contains no multi valued dependencies

Course Instructor Course Textbook


Management White Management Drucker
Management Green Management Peters
Management Black Finance Weston
Finance Gray Finance Gilford 32
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)

• Cope up with Join dependency

• Join Dependency:
• Relation cannot be divided into two relations
• And then the resulting relations cannot be recombined to form the original
relation

• It’s very rare in normal situations

34
35

You might also like