0% found this document useful (0 votes)
21 views15 pages

Normalization and Denormalization

Uploaded by

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

Normalization and Denormalization

Uploaded by

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

Partial, Full, and Transitive Dependencies

Functional Dependency is a key feature of a Database management System.

Functional Dependency is used to maintain the relationship between various

attributes in a given database.

What is Functional Dependency?

Functional dependency states the relationship between two sets of attributes

where a value of a set of attributes is dependent on the other set of attributes.

It is a relationship that typically exists between two attributes such that with the

help of one attribute we can get the values of another attribute. The attribute

that is used for finding the values of other attributes is called the primary key

attribute.

Why is Functional Dependency Used?

 To maintain Data Integrity

 Easy to maintain

 Efficient Data Storage

 Improved Data Redundancy


Example

We have a table with student details such as roll number, name, and city.

roll_no name city

1 Yash Delhi

2 Kartik Mumbai

3 Aditya Delhi

4 Kartik Pune

Here roll_no is only unique attribute. So the primary key for the given table will

be roll_no. Other attributes such as name and city are dependent on the

roll_no i.e. on the basis of roll_no we can get student’s name and its city.But

we can not get roll_no of student based on it’s name or city as it will create

ambiguity.

For example, if we take name as kartik there will be 2 records with the name

kartik which will result into ambiguity. Also if we take city as Delhi there will be

2 records i.e. roll_no 1 and roll_no 3.


So here we can say that name and city are functionally dependent on roll_no.

Types of Dependencies

 Partial Dependency

 Full Dependency

 Transitive Dependency

Partial Dependency

If the value of a non-primary attribute can be defined using part of the primary

key then it is called a partial dependency. Partial dependency occurs when

primary key is formed using more than one attribute.This type of key also

called as composite key.

In below given example, the primary key is formed using roll_no + sub_id

which can also be called as composite key.When composite key is present

and one of the non-primary attribute can is dependent on part of the primary

key instead of whole primary key then it is called as Partial Dependency.

Example

Let’s take an example, we have a table where we have columns of student roll

number, subject ID, sub name, and marks obtained.


Table
roll_no sub_id sub_name sub_mark

1 121 Science 80

1 131 Math 65

2 131 Math 95

2 141 English 75

Here primary key will be roll_no+ sub_id because multiple roll_no can have

the same sub_id and the same roll_no can have multiple sub_id.In the given

example, roll_no 1 has two sub_id i.e. 121 and 131 where as sub_id 131 has

two roll_no 1 and 2.So here primary key will be roll_no + sub_id.

But we do have another column of sub_name and the value of sub_name can

be easily obtained by only sub_id which is part of the primary key.For

example, sub_id = 131 will have the sub_name = ‘math’ here we required only

partial primary key i.e. sub_id.

This type of functional Dependency is known as Partial Dependency.

Full Dependency
If all attributes of the primary key are required for the identifying value of a non-

primary attribute then it is known as Full Dependency.

When all non-primary attribute are dependent on whole primary key and they

cannot be get defined using only partial part of primary key then it is called as

Full Dependency.

If the dependency is non-partial dependency then it can be called as Full

Deppendency also.

Example

Let’s take an example, we have a table where we have columns of student roll

number, subject ID, and marks obtained.

Table
roll_no sub_id marks

1 121 80

1 131 65

2 131 95

2 141 75
Here the primary key is roll_no+ sub_id. If we want a mark of any student, we

require both roll_no and sub_id. We cannot obtain marks based on one

attribute from the primary key.

If we want to know the marks of sub_id=131 there will be two records and

ambiguity will be created. If we take roll_id=1 there will be two records with the

same roll number and ambiguity will be created here.This ambiguity will be

solved using full attributes of the primary key i.e. roll_no + sub_id. So we

required the full attributes of the primary key.

This type of functional Dependency is known as Full Dependency.

Transitive Dependency

If the value of a non-primary attribute can be defined using another non-

primary attribute then it is called a transitive dependency.

When any attribute does not require primary key and can easily get value

using another non-primary attribute then it is called as Transitive Dependency.

Example

Let’s take an example, we have a table where we have columns of student roll

number, name, city where student live, and zip-code of city .


Table
roll_no name city zip-code

1 abc pune 411044

2 jkl mumbai 400001

3 uvw pune 411044

4 xyz delhi 110001

Here the primary key is roll_no but we can identify the city using zip-code

where city and zip-code both are the primary key

So here roll_no → city and city→zip-code eventually resulting into roll_no

→zip-code. so we can find a non-primary attribute using another non-primary

attribute.For example, roll-no = 1 has city=pune and city=pune will have zip-

code=411044.So wherever city is pune , zip-code will be 411044

This type of functional Dependency is known as Transitive Dependency.

Partial, Full, and Transitive Dependency – FAQs

Which normal form is based on partial dependency?


2NF(second normal form ) is used to eliminate the partial dependencies

present in the database.

Which normal form is based on transitive dependency?

3NF(third normal form ) is used to eiminate the transitives dependencies

present in database.

Why are partial and transitive dependencies are bad?


Because they create problems in database management. Due to this type of

dependency, they create redundancy issue , inconsistency in data and many

more issues.So we need to avoid this type of dependencies .

How to avoid transitive dependency?

To avoid transitive dependency, a new table should be created using the non

prime attributes which have relation with each other .New table should have its

primary key and a refernce to the previous table via foreign key.

How to avoid transitive dependency?


The partial primary key attribute with its dependent attribute is removed from

the table and kept in a new table with new relation where non prime attribute

are now fully dependent on primary key atrributes.

What Is Normalization?
Normalization is the process of organizing (decomposing) the data in a relational
database in accordance with a series of normal forms in order to reduce data
redundancy, improve data integrity and to remove Insert, Update and Delete
Anomalies.

By normalizing a database, you arrange the data into tables and columns. You ensure
that each table contains only related data. If data is not directly related, you create a
new table for that data. Normalization is an important part of relational database design
for many reasons, but mainly because it allows database to take up as little disk space
as possible, resulting in increased speed, accuracy and efficiency of the database.

Three main types of normalization or normal forms (NF) are:

 1NF
 2NF
 3NF
 BCNF
 4NF
 5NF

What You Need To Know About Normalization


1. Normalization is the process of organizing (decomposing) the data in a
relational database in accordance with a series of normal forms in order to
reduce data redundancy, improve data integrity and to remove Insert, Update
and Delete Anomalies.
2. Normalization is used in OLTP system which emphasizes on making the insert,
delete and update anomalies faster.
3. Normalization main focus is on clearing the database from unused data and to
reduce the data redundancy and inconsistency.
4. Normalization removes data redundancy i.e. It eliminates any duplicate data
from the same table and puts it into a separate new table.
5. In normalization, memory space is optimized because duplicate data is
organized and stored in different places (tables).
6. Normalization maintains data integrity i.e any addition or deletion of data
from the table will not create any mismatch in the relationship of the tables.
7. Normalization is generally used where number of insert/update/delete
operations are performed and joins of those tables are not expensive.
8. During Normalization as data is reduced so a number of tables are deleted
from the database hence tables are lesser in number.
9. Even though normalization creates multiple tables, insert, update and delete
are more efficient in this regard. If we have to insert/update/delete any data,
we have to perform the transaction in that particular table. Therefore, there is
no fear of data loss (data integrity).

What Is Denormalization?
Denormalization is the process where data from multiple tables are combined into a
single table, so that data retrieval will be faster. Denormalization is a strategy that
database managers use to increase the performance of a database infrastructure.

Usually denormalization entails creating separate tables or structures so that queries on


one piece of information will not affect any other information tied to it. When a query
combines data from multiple tables into a single result table, it is referred to as a join.
The performance of such a join in the face of complex queries is often the occasion for
the administrator to explore the denormalization alternative.

The main methods of denormalization are:


 Adding Redundant columns
 Adding derived columns
 Collapsing the tables
 Snapshots
 VARRAYS
 Materialized Views

What You Need To Know About Denormalization


1. Denormalization is the process where data from multiple tables are combined
into one table, so that data retrieval will be faster.
2. Denormalization is used in OLAP system which emphasizes on making the
search and analysis faster.
3. Denormalization main focus is to achieve faster execution of the queries
through introducing redundancy.
4. Denormalization creates data redundancy i.e duplicate data may be found in
the same table.
5. Memory space is not optimized in denormalization because duplicate data is
stored in a single place (table).
6. Denormalization does not maintain any data integrity.
7. Denormalization is used where joins are expensive and frequent query is
executed on the tables.
8. In denormalization, all duplicate data is in a single table and care need to be
taken into account when inserting/updating or deleting all related data in that
table. Failure in doing that can give rise to integrity issues.
9. During Denormalization data is integrated into the same database and hence
a number of tables to store that data increases in number.
Also Read: Difference Between OODBMS And ORDBMS

Difference Between Normalization And


Denormalization In SQL, In Tabular Form
BASIS OF
NORMALIZATION DEMORMALIZATION
COMPARISON
It is the process of organizing
(decomposing) the data in a
relational database in accordance It is the process where data from
with a series of normal forms in multiple tables are combined into
Description
order to reduce data redundancy, one table, so that data retrieval
improve data integrity and to will be faster.
remove Insert, Update and Delete
Anomalies.

It is used in OLTP system which


It is used in OLAP system which
emphasizes on making the insert,
Application emphasizes on making the
delete and update anomalies
search and analysis faster.
faster.

Main focus is on clearing the


Main focus is to achieve faster
database from unused data and
Main Focus execution of the queries through
to reduce the data redundancy
introducing redundancy.
and inconsistency.

It removes data redundancy i.e.


It creates data redundancy i.e
Data It eliminates any duplicate data
duplicate data may be found in
Redundancy from the same table and puts it
the same table.
into a separate new table.

Memory space is optimized Memory space is not optimized in


Memory
because duplicate data is denormalization because
Space
organized and stored in different duplicate data is stored in a
Optimization
places (tables). single place (table).

Maintains data integrity i.e any


addition or deletion of data from
It does not maintain any data
Data Integrity the table will not create any
integrity.
mismatch in the relationship of
the tables.

It is generally used where


number of insert/update/delete It is used where joins are
Use operations are performed and expensive and frequent query is
joins of those tables are not executed on the tables.
expensive.

All duplicate data is in a single


table and care need to be taken
As data is reduced so a number
into account when
Duplicate of tables are deleted from the
inserting/updating or deleting all
Data database hence tables are lesser
related data in that table. Failure
in number.
in doing that can give rise to
integrity issues.

Number Of Even though normalization Data is integrated into the same


Data creates multiple tables, insert, database and hence a number of
update and delete are more tables to store that data
efficient in this regard. increases in number.

Advantages of Normalization
 Users can extent the database without necessarily impacting the exiting data.
 Minimizes null values
 Helps to reduce or avoid modification problems
 Searching, sorting and creating indexes can be faster since tables are
narrower and more rows fit on a data page.
 Simplifies queries
 Makes database smaller by eliminating redundant data.
 It delete anomalies that will cause an error in the system.
 Does not waste storage space
 It results in a more compact database (due to less data redundancy)
 It results in database being simpler and easier to understand.

Disadvantages of Normalization
 Normalization is a very difficult task because it requires detailed analysis and
design of the database.
 Normalization creates a tedious task, because there are more tables to join
 Normalization results in results in slow performance of the entire database
system because tables contain codes rather than real data.
 It makes the query more difficult, because it consists of an SQL that is
constructed dynamically and is usually constructed by desktop friendly query
tools, hence it is hard to model the database without knowing what the
customers desires.
 A poorly normalized database may perform badly and store data inefficiently.
 Normalizing a database is sometimes complex because analysts have to
understand the purpose of the database such as whether it should be
optimized for writing data, reading data or both.
Advantages Of Denormalization
 It reduces the number of foreign keys and indexes. This helps to save on data
manipulation time and memory as well.
 It minimizes the number of necessary join queries
 In some cases, it reduces number of tables in the database.
 Improves performance of the database by increasing speed

Disadvantages Of Denormalization
 Denormalization usually speeds retrieval but can slow updates.
 Denormalization is always application specific and therefore requires to be
evaluated if the application changes.
 Denormalization can increase the size of tables.
 Denormalization can make update and insert code difficult to write.
 Data redundancy necessitates more storage.
 Denormalization does not maintain any data integrity.
 Waste storage space.

You might also like