You are on page 1of 29

ST.

ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM


RELATIONAL DATABASE MANAGEMENT SYSTEM

UNIT –IV

DATA NORMALIZATION
PITFALLS IN RELATIONAL DATABASE DESIGN

Pitfalls in Relational database Design Relational database design requires that we find a
“good” collection of relational schemas.

A bad design may lead to—

 Repetition of information
 Inability to represent certain information
 Loss of information.

Design Goals for Relational Database

1. Avoid redundant data

2. Ensure that relationships among attributes are represented.

3. Facilitate the checking of updates for violation of database integrity constraints

Example Consider the relational schema Lending-schema = (branch-name, branch-


city, assets, customer-name, loan- number, amount)

The relation lending with the schema is an example of a bad design:

Lending-Schema=(branch-name, branch-city, assets, cutomer-name, loan-number,


amount)

branch-name branch-city assets customer-name loan-number amount


Downtown Brooklyn 9000000 Jones L-17 1000
Redwood Palo Alto 2100000 Smith L-23 2000
Perryridge Horseneck 1700000 Hayes L-15 1500
Downtown Brooklyn 9000000 Jackson L-14 1500
Mianus Horseneck 400000 Jones L-93 500
Round Hill Horseneck 8000000 Turner L-11 900
Pownal Bennington 300000 Williams L-29 1200
North Town Rye 3700000 Hayes L-16 1300
Downtown Brooklyn 9000000 Johnson L-23 2000

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
Perryridge Horseneck 1700000 Glenn L-25 2500
Brighton Brooklyn 7100000 Brooks L-10 2200

Looking at the Downtown and Perryridge, when a new loan is added, the branch-city
and assets must be repeated. That makes updating the table more difficult, because the
update must guarantee that all tuples are updated. Additional problems come from having
two people take out one loan (L-23). More complexity is involved when Jones took out a
loan at a second branch (maybe one near home and the other near work.) Notice that there is
no way to represent information on a branch unless there is a loan.

Redundancy --Data for branch name, branch city, assets are repeated for each loan
that a branch makes. --Wastes space and complicates updating.

Null Values - cannot store information about a branch if no loan exists

can use null values, but they are difficult to handle.


In the given example the database design is faulty which makes the above pitfalls in
database.
So we observe that in relational database design if the design is not good then there
will be faults in databases

Decomposition

The obvious solution is that we should decompose this relation. As an alternative


design, we can use the Decomposition

rule: If A implies BC then A implies B and A implies C.

This gives us the schemas:

 branch-customer-schema = (branch-name, branch-city, assets, customer-name)


 customer-loan-schema = (customer-name, loan-number, amount)

branch-name branch-city assets customer-name


Downtown Brooklyn 9000000 Jones
Redwood Palo Alto 2100000 Smith
Perryridge Horseneck 1700000 Hayes
Downtown Brooklyn 9000000 Jackson
Mianus Horseneck 400000 Jones
Round Hill Horseneck 8000000 Turner
Pownal Bennington 300000 Williams

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
North Town Rye 3700000 Hayes
Downtown Brooklyn 9000000 Johnson
Perryridge Horseneck 1700000 Glenn
Brighton Brooklyn 7100000 Brooks

customer-name loan-number amount


Jones L-17 1000
Smith L-23 2000
Hayes L-15 1500
Jackson L-14 1500
Jones L-93 500
Turner L-11 900
Williams L-29 1200
Hayes L-16 1300
Johnson L-23 2000
Glenn L-25 2500
Brooklyn L-10 2200
Then when we need to get back to the original table, we can do a natural join on the two
relations branch-customer and customer-loan.

Evaluating this design, how does it compare to the first version?

 Looking at the Downtown and Perryridge, when a new loan is added, the branch-city
and assets must be repeated. Problem still exists.
 Problems come from having two people take out one loan (L-23). Problem still
exists.
 More complexity is involved when Jones took out a loan at a second branch. Problem
still exists.
 Notice that there is no way to represent information on a branch unless there is a
loan. Problem still exists.

Worse, there is a new problem! When we do the natural join, we get back four additional
tuples that did not exists in the original table:

 (Downtown, Brooklyn, 9000000, Jones, L-93, 500)


 (Perryridge, Horseneck, 1700000, Hayes, L-16, 1300)
 (Mianus, Horseneck, 400000, Jones, L-17, 1000)
 (North Town, Rye, 3700000, Hayes, L-15, 1500)

We are no long able to represent in the database information about which customers are
borrows from which branch. This is called a lossy decomposition or lossy-join
decomposition. A decomposition that is not a lossy-decomposition is a lossless-join
decomposition. Lossless-joins are a requirement for good design and this causes constraints

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
on the set of possible relations. We say that a relation is legal if it satisfies all rules, or
constraints, imposed.

The proper way to decomposition this example so that we can have a lossless-join is to use
three relations.

 branch-schema = (branch-name, assets, branch-city)


 loan-schema = (branch-name, loan-number, amount)
 borrower-schema = (customer-name, loan-number)

Functional Dependency

Functional dependency (FD) is a set of constraints between two attributes in a


relation. Functional dependency says that if two tuples have same values for attributes A1,
A2,..., An, then those two tuples must have to have same values for attributes B1, B2, ..., Bn.

Functional dependency is represented by an arrow sign (→) that is, X→Y, where X
functionally determines Y. The left-hand side attributes determine the values of attributes on
the right-hand side.

Armstrong's Axioms

If F is a set of functional dependencies then the closure of F, denoted as F+, is the set of all
functional dependencies logically implied by F. Armstrong's Axioms are a set of rules, that
when applied repeatedly, generates a closure of functional dependencies.

 Reflexive rule − If alpha is a set of attributes and beta is_subset_of alpha, then alpha
holds beta.

 Augmentation rule − If a → b holds and y is attribute set, then ay → by also holds.


That is adding attributes in dependencies, does not change the basic dependencies.

 Transitivity rule − Same as transitive rule in algebra, if a → b holds and b → c


holds, then a → c also holds. a → b is called as a functionally that determines b.

Trivial Functional Dependency

 Trivial − If a functional dependency (FD) X → Y holds, where Y is a subset of X,


then it is called a trivial FD. Trivial FDs always hold.

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
 Non-trivial − If an FD X → Y holds, where Y is not a subset of X, then it is called a
non-trivial FD.

 Completely non-trivial − If an FD X → Y holds, where x intersect Y = Φ, it is said


to be a completely non-trivial FD.

What is Normalization?

Normalization is a database design technique that reduces data redundancy and


eliminates undesirable characteristics like Insertion, Update and Deletion Anomalies.
Normalization rules divides larger tables into smaller tables and links them using
relationships. The purpose of Normalization in SQL is to eliminate redundant (repetitive)
data and ensure data is stored logically.

The inventor of the relational model Edgar Codd proposed the theory of normalization of data
with the introduction of the First Normal Form, and he continued to extend theory with
Second and Third Normal Form. Later he joined Raymond F. Boyce to develop the theory of
Boyce-Codd Normal Form.

o Normalization is the process of organizing the data in the database.


o Normalization is used to minimize the redundancy from a relation or set of relations.
It is also used to eliminate undesirable characteristics like Insertion, Update, and
Deletion Anomalies.
o Normalization divides the larger table into smaller and links them using relationships.
o The normal form is used to reduce redundancy from the database table.

Why do we need Normalization?

The main reason for normalizing the relations is removing these anomalies. Failure to
eliminate anomalies leads to data redundancy and can cause data integrity and other problems
as the database grows. Normalization consists of a series of guidelines that helps to guide you
in creating a good database structure.ndia (1947-2020)

Data modification anomalies can be categorized into three types:

o Insertion Anomaly: Insertion Anomaly refers to when one cannot insert a new tuple
into a relationship due to lack of data.

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

o Deletion Anomaly: The delete anomaly refers to the situation where the deletion of
data results in the unintended loss of some other important data.
o Updatation Anomaly: The update anomaly is when an update of a single data value
requires multiple rows of data to be updated.

Database Normal Forms

Here is a list of Normal Forms

 1NF (First Normal Form)


 2NF (Second Normal Form)
 3NF (Third Normal Form)
 BCNF (Boyce-Codd Normal Form)
 4NF (Fourth Normal Form)
 5NF (Fifth Normal Form)
 6NF (Sixth Normal Form)

`The Theory of Data Normalization in SQL server is still being developed further. For
example, there are discussions even on 6th Normal Form. However, in most practical
applications, normalization achieves its best in 3rd Normal Form.

Normalization works through a series of stages called Normal forms. The normal
forms apply to individual relations. The relation is said to be in particular normal form if it
satisfies constraints.

The evolution of SQL Normalization theories is illustrated below-x Linux Beginner Tutorial

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

Database Normal Forms

Following are the various types of Normal forms:

Normal Description
Form

1NF A relation is in 1NF if it contains an atomic value.

2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully
functional dependent on the primary key.

3NF A relation will be in 3NF if it is in 2NF and no transition dependency exists.

BCNF A stronger definition of 3NF is known as Boyce Codd's normal form.

4NF A relation will be in 4NF if it is in Boyce Codd's normal form and has no multi-
valued dependency.

5NF A relation is in 5NF. If it is in 4NF and does not contain any join dependency,
joining should be lossless.

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

Normalization

A large database defined as a single relation may result in data duplication. This
repetition of data may result in:

o Making relations very large.


o It isn't easy to maintain and update data as it would involve searching many records
in relation.
o Wastage and poor utilization of disk space and resources.
o The likelihood of errors and inconsistencies increases.

So to handle these problems, we should analyze and decompose the relations with
redundant data into smaller, simpler, and well-structured relations that are satisfy
desirable properties. Normalization is a process of decomposing the relations into
relations with fewer attributes.

If a database design is not perfect, it may contain anomalies, which are like a bad dream for
any database administrator. Managing a database with anomalies is next to impossible.

 Update anomalies − If data items are scattered and are not linked to each other
properly, then it could lead to strange situations. For example, when we try to update
one data item having its copies scattered over several places, a few instances get
updated properly while a few others are left with old values. Such instances leave the
database in an inconsistent state.

 Deletion anomalies − We tried to delete a record, but parts of it was left undeleted
because of unawareness, the data is also saved somewhere else.

 Insert anomalies − We tried to insert data in a record that does not exist at all.

Normalization is a method to remove all these anomalies and bring the database to a
consistent state.

Advantages of Normalization

o Normalization helps to minimize data redundancy.


o Greater overall database organization.

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

o Data consistency within the database.


o Much more flexible database design.
o Enforces the concept of relational integrity.

Disadvantages of Normalization

o You cannot start building the database before knowing what the user needs.
o The performance degrades when normalizing the relations to higher normal forms,
i.e., 4NF, 5NF.
o It is very time-consuming and difficult to normalize relations of a higher degree.
o Careless decomposition may lead to a bad database design, leading to serious
problems.

First Normal Form (1NF)


o A relation will be 1NF if it contains an atomic value.
o It states that an attribute of a table cannot hold multiple values. It must hold only
single-valued attribute.
o First normal form disallows the multi-valued attribute, composite attribute, and their
combinations.

Example: Relation EMPLOYEE is not in 1NF because of multi-valued attribute


EMP_PHONE.

EMPLOYEE table:

EMP_ID EMP_NAME EMP_PHONE EMP_STATE

14 John 7272826385, UP
9064738238

20 Harry 8574783832 Bihar

12 Sam 7390372389, Punjab


8589830302

The decomposition of the EMPLOYEE table into 1NF has been shown below:

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

EMP_ID EMP_NAME EMP_PHONE EMP_STATE

14 John 7272826385 UP

14 John 9064738238 UP

20 Harry 8574783832 Bihar

12 Sam 7390372389 Punjab

12 Sam 8589830302 Punjab

Each attribute must contain only a single value from its pre-defined domain.

Second Normal Form

Second Normal Form (2NF)


o In the 2NF, relational must be in 1NF.
o In the second normal form, all non-key attributes are fully functional dependent on the
primary key

Before we learn about the second normal form, we need to understand the following −

 Prime attribute − An attribute, which is a part of the candidate-key, is known as a


prime attribute.

 Non-prime attribute − An attribute, which is not a part of the prime-key, is said to


be a non-prime attribute.

Example: Let's assume, a school can store the data of teachers and the subjects they teach. In
a school, a teacher can teach more than one subject.

TEACHER table

TEACHER_ID SUBJECT TEACHER_AGE

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

25 Chemistry 30

25 Biology 30

47 English 35

83 Math 38

83 Computer 38

In the given table, non-prime attribute TEACHER_AGE is dependent on TEACHER_ID


which is a proper subset of a candidate key. That's why it violates the rule for 2NF.

To convert the given table into 2NF, we decompose it into two tables:.3M7

TEACHER_DETAIL table:

TEACHER_ID TEACHER_AGE

25 30

47 35

83 38

TEACHER_SUBJECT table:

TEACHER_ID SUBJECT

25 Chemistry

25 Biology

47 English

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

83 Math

83 Computer

Third Normal Form

Third Normal Form (3NF)

o A relation will be in 3NF if it is in 2NF and not contain any transitive partial
dependency.
o 3NF is used to reduce the data duplication. It is also used to achieve the data integrity.
o If there is no transitive dependency for non-prime attributes, then the relation must be
in third normal form.

A relation is in third normal form if it holds atleast one of the following conditions for every
non-trivial function dependency X → Y.

1. X is a super key.
2. Y is a prime attribute, i.e., each element of Y is part of some candidate key.

For a relation to be in Third Normal Form, it must be in Second Normal form and the
following must satisfy –

 No non-prime attribute is transitively dependent on prime key attribute.

 For any non-trivial functional dependency, X → A, then either –

Example:

EMPLOYEE_DETAIL table:

EMP_ID EMP_NAME EMP_ZIP EMP_STATE EMP_CITY

222 Harry 201010 UP Noida

333 Stephan 02228 US Boston

444 Lan 60007 US Chicago

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

555 Katharine 06389 UK Norwich

666 John 462007 MP Bhopal

Super key in the table above:

{EMP_ID}, {EMP_ID, EMP_NAME}, {EMP_ID, EMP_NAME, EMP_ZIP}....so on

Candidate key: {EMP_ID}

Non-prime attributes: In the given table, all attributes except EMP_ID are non-
prime.

Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP dependent on


EMP_ID. The non-prime attributes (EMP_STATE, EMP_CITY) transitively dependent on
super key(EMP_ID). It violates the rule of third normal form.

That's why we need to move the EMP_CITY and EMP_STATE to the new
<EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary key.

EMPLOYEE table:

EMP_ID EMP_NAME EMP_ZIP

222 Harry 201010

333 Stephan 02228

444 Lan 60007

555 Katharine 06389

666 John 462007

EMPLOYEE_ZIP table:

EMP_ZIP EMP_STATE EMP_CITY

201010 UP Noida

02228 US Boston

60007 US Chicago

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

06389 UK Norwich

462007 MP Bhopal

Boyce Codd normal form (BCNF)


o BCNF is the advance version of 3NF. It is stricter than 3NF.
o A table is in BCNF if every functional dependency X → Y, X is the super key of the
table.
o For BCNF, the table should be in 3NF, and for every FD, LHS is super key.

Example: Let's assume there is a company where employees work in more than one
department.

EMPLOYEE table:

EMP_ID EMP_COUNTRY EMP_DEPT DEPT_TYPE EMP_DEPT_NO

264 India Designing D394 283

264 India Testing D394 300

364 UK Stores D283 232

364 UK Developing D283 549

In the above table Functional dependencies are as follows:

1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}

Candidate key: {EMP-ID, EMP-DEPT} find Nth Highest Salary in SQL

The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.

To convert the given table into BCNF, we decompose it into three tables:

EMP_COUNTRY table:

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

EMP_ID EMP_COUNTRY

264 India

264 India

EMP_DEPT table:

EMP_DEPT DEPT_TYPE EMP_DEPT_NO

Designing D394 283

Testing D394 300

Stores D283 232

Developing D283 549

EMP_DEPT_MAPPING table:

EMP_ID EMP_DEPT

D394 283

D394 300

D283 232

D283 549

Functional dependencies:

1. EMP_ID → EMP_COUNTRY

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}

Candidate keys:

For the first table: EMP_ID


For the second table: EMP_DEPT
For the third table: {EMP_ID, EMP_DEPT}

Now, this is in BCNF because left side part of both the functional dependencies is a
key.

Fourth normal form (4NF)


o A relation will be in 4NF if it is in Boyce Codd normal form and has no multi-valued
dependency.
o For a dependency A → B, if for a single value of A, multiple values of B exists, then the
relation will be a multi-valued dependency.

Example
STUDENT

STU_ID COURSE HOBBY

21 Computer Dancing

21 Math Singing

34 Chemistry Dancing

74 Biology Cricket

59 Physics Hockey

The given STUDENT table is in 3NF, but the COURSE and HOBBY are two independent
entity. Hence, there is no relationship between COURSE and HOBBY.

In the STUDENT relation, a student with STU_ID, 21 contains two


courses, Computer and Math and two hobbies, Dancing and Singing. So there is a Multi-
valued dependency on STU_ID, which leads to unnecessary repetition of data.

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
So to make the above table into 4NF, we can decompose it into two tables:

STUDENT_COURSE

STU_ID COURSE

21 Computer

21 Math

34 Chemistry

74 Biology

59 Physics

STUDENT_HOBBY

STU_ID HOBBY

21 Dancing

21 Singing

34 Dancing

74 Cricket

59 Hockey

Fifth normal form (5NF)


o A relation is in 5NF if it is in 4NF and not contains any join dependency and joining
should be lossless.
o 5NF is satisfied when all the tables are broken into as many tables as possible in
order to avoid redundancy.
o 5NF is also known as Project-join normal form (PJ/NF).

Example
SUBJECT LECTURER SEMESTER

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

Computer Anshika Semester 1

Computer John Semester 1

Math John Semester 1

Math Akash Semester 2

Chemistry Praveen Semester 1

In the above table, John takes both Computer and Math class for Semester 1 but he
doesn't take Math class for Semester 2. In this case, combination of all these fields
required to identify a valid data.

Suppose we add a new Semester as Semester 3 but do not know about the subject
and who will be taking that subject so we leave Lecturer and Subject as NULL. But all
three columns together acts as a primary key, so we can't leave other two columns
blank.

So to make the above table into 5NF, we can decompose it into three relations P1, P2
& P3:

P1

SEMESTER SUBJECT

Semester 1 Computer

Semester 1 Math

Semester 1 Chemistry

Semester 2 Math

P2

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

SUBJECT LECTURER

Computer Anshika

Computer John

Math John

Math Akash

Chemistry Praveen

P3

SEMSTER LECTURER

Semester 1 Anshika

Semester 1 John

Semester 1 John

Semester 2 Akash

Semester 1 Praveen

Normalization of Database
Database Normalization is a technique of organizing the data in the database. Normalization
is a systematic approach of decomposing tables to eliminate data redundancy(repetition) and
undesirable characteristics like Insertion, Update and Deletion Anomalies. It is a multi-step
process that puts data into tabular form, removing duplicated data from the relation tables.

Normalization is used for mainly two purposes,

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
 Eliminating redundant(useless) data.
 Ensuring data dependencies make sense i.e data is logically stored.

Problems Without Normalization

If a table is not properly normalized and have data redundancy then it will not only eat up
extra memory space but will also make it difficult to handle and update the database, without
facing data loss. Insertion, Updation and Deletion Anomalies are very frequent if database is
not normalized. To understand these anomalies let us take an example of a Student table.

rollno name branch hod office_tel

401 Akon CSE Mr. X 53337

402 Bkon CSE Mr. X 53337

403 Ckon CSE Mr. X 53337

404 Dkon CSE Mr. X 53337

In the table above, we have data of 4 Computer Sci. students. As we can see, data for the
fields branch, hod(Head of Department) and office_tel is repeated for the students who are in
the same branch in the college, this is Data Redundancy.

Insertion Anomaly

Suppose for a new admission, until and unless a student opts for a branch, data of the student
cannot be inserted, or else we will have to set the branch information as NULL.

Also, if we have to insert data of 100 students of same branch, then the branch information
will be repeated for all those 100 students.

These scenarios are nothing but Insertion anomalies.

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
Updation Anomaly

What if Mr. X leaves the college? or is no longer the HOD of computer science department?
In that case all the student records will have to be updated, and if by mistake we miss any
record, it will lead to data inconsistency. This is Updation anomaly.

Deletion Anomaly

In our Student table, two different informations are kept together, Student information and
Branch information. Hence, at the end of the academic year, if student records are deleted, we
will also lose the branch information. This is Deletion anomaly.

Database Normalization With Examples

Database Normalization Example can be easily understood with the help of a case study.
Assume, a video library maintains a database of movies rented out. Without any
normalization in database, all information is stored in one table as shown below. Let's
understand Normalization in database with tables example:

Table 1

Here you see Movies Rented column has multiple values. Now let's move into 1st Normal
Forms:

1NF (First Normal Form) Rules

 Each table cell should contain a single value.

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
 Each record needs to be unique.

The above table in 1NF-

1NF Example

Table 1: In 1NF Form

Before we proceed let's understand a few things --

What is a KEY?

A KEY is a value used to identify a record in a table uniquely. A KEY could be a single
column or combination of multiple columns

Note: Columns in a table that are NOT used to identify a record uniquely are called non-key
columns.

What is a Primary Key?

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
A primary is a single column value used to identify a database record uniquely.

It has following attributes

 A primary key cannot be NULL


 A primary key value must be unique
 The primary key values should rarely be changed
 The primary key must be given a value when a new record is inserted.

What is Composite Key?

A composite key is a primary key composed of multiple columns used to identify a record
uniquely

In our database, we have two people with the same name Robert Phil, but they live in
different places.

Hence, we require both Full Name and Address to identify a record uniquely. That is a
composite key.

Let's move into second normal form 2NF

2NF (Second Normal Form) Rules

 Rule 1- Be in 1NF
 Rule 2- Single Column Primary Key

It is clear that we can't move forward to make our simple database in 2nd Normalization form
unless we partition the table above.

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

Table 1

Table 2

We have divided our 1NF table into two tables viz. Table 1 and Table2. Table 1 contains
member information. Table 2 contains information on movies rented.

We have introduced a new column called Membership_id which is the primary key for table
1. Records can be uniquely identified in Table 1 using membership id

Database - Foreign Key

In Table 2, Membership_ID is the Foreign Key

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

Foreign Key references the primary key of another Table! It helps connect your Tables

 A foreign key can have a different name from its primary key
 It ensures rows in one table have corresponding rows in another
 Unlike the Primary key, they do not have to be unique. Most often they aren't
 Foreign keys can be null even though primary keys can not

Why do you need a foreign key?

Suppose, a novice inserts a record in Table B such as

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM

You will only be able to insert values into your foreign key that exist in the unique key in the
parent table. This helps in referential integrity.

The above problem can be overcome by declaring membership id from Table2 as foreign
key of membership id from Table1

Now, if somebody tries to insert a value in the membership id field that does not exist in the
parent table, an error will be shown!

What are transitive functional dependencies?

A transitive functional dependency is when changing a non-key column, might cause any of
the other non-key columns to change

Consider the table 1. Changing the non-key column Full Name may change Salutation.

Let's move into 3NF

3NF (Third Normal Form) Rules

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
 Rule 1- Be in 2NF
 Rule 2- Has no transitive functional dependencies

To move our 2NF table into 3NF, we again need to again divide our table.

3NF Example

Below is a 3NF example in SQL database:

TABLE 1

Table 2

Table 3

We have again divided our tables and created a new table which stores Salutations.

There are no transitive functional dependencies, and hence our table is in 3NF

In Table 3 Salutation ID is primary key, and in Table 1 Salutation ID is foreign to primary


key in Table 3

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
Now our little example is at a level that cannot further be decomposed to attain higher normal
forms of normalization. In fact, it is already in higher normalization forms. Separate efforts
for moving into next levels of normalizing data are normally needed in complex databases.

BCNF (Boyce-Codd Normal Form)

Even when a database is in 3rd Normal Form, still there would be anomalies resulted if it has
more than one Candidate Key.

Sometimes is BCNF is also referred as 3.5 Normal Form.

4NF (Fourth Normal Form) Rules

If no database table instance contains two or more, independent and multivalued data
describing the relevant entity, then it is in 4th Normal Form.

5NF (Fifth Normal Form) Rules

A table is in 5th Normal Form only if it is in 4NF and it cannot be decomposed into any
number of smaller tables without loss of data.

6NF (Sixth Normal Form) Proposed

6th Normal Form is not standardized, yet however, it is being discussed by database experts
for some time. Hopefully, we would have a clear & standardized definition for 6th Normal
Form in the near future...

That's all to SQL Normalization!!!

Summary

 Database designing is critical to the successful implementation of a database


management system that meets the data requirements of an enterprise system.
 Normalization Process in DBMS helps produce database systems that are cost-
effective and have better security models.
 Functional dependencies are a very important component of the normalize data
process

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV


ST.ANN’S COLLEGE OF ARTS AND SCIENCE, TINDIVANAM
RELATIONAL DATABASE MANAGEMENT SYSTEM
 Most database systems are normalized database up to the third normal forms.
 A primary key uniquely identifies are record in a Table and cannot be null
 A foreign key helps connect table and references a

DEPARTMENT OF COMPUTER SCIENCE SEMESTER: IV

You might also like