You are on page 1of 14

Normalization 1

Assignment of Computer
Normalization

B.S Islamic Studies


(2018-2022)

Submitted to: Miss Saima Yousaf


Submitted by: Ayema Sarwar
Roll No: F-1848

Sheikh Zayed Islamic Centre Punjab


University Lahore

Punjab University Sheikh Zayed Islamic Centre


Normalization 2

Table of Content
1.Definition of Normalization
2.Basic concepts of Normalization
•Partial Dependency
•Transitive Dependency
•Anomalies

1.What is Entity and Attributes


2.Types of Normalization
•First Normal Form (1NF)
•Second Normal Form (2NF)
•Third Normal Form (3NF)
•Boyce-Codd Normal Form (BCNF)
•Fourth Normal Form (4NF)
•Fifth Normal Form (5NF)

Punjab University Sheikh Zayed Islamic Centre


Normalization 3

Normalization
(1)In relational database design, the process of organizing data to minimize
redundancy. Normalization usually involves dividing a database into two or more tables and defining
relationships between the tables. ... For example, in an employee list, each table would contain only
one birthdate field.
(2) In relational database design, the process of organizing data to minimize redundancy. Normalization
usually involves dividing a database into two or more tables and defining relationships between the
tables. The objective is to isolate data so that additions, deletions, and modifications of a fieldcan be
made in just one table and then propagated through the rest of the database via the defined
relationships.
(3)Normalization is a process of organizing the data in database to avoid data redundancy,
insertion anomaly, update anomaly & deletion anomaly. Let’s discuss about anomalies first then we
will discuss normal forms with examples.

Basic concepts of Normalization:


•Partial dependency
•Transitive dependency
•Anomalies

What is Entity and Attributes:


Entities are represented by means of their properties, called attributes. Allattributes have values. For
example, a student entity may have name, class, and age as attributes. There exists a domain or range of
values that can be assigned toattributes

Anomalies in DBMS
There are three types of anomalies that occur when the database is not normalized. These are –
Insertion, update and deletion anomaly. Let’s take an example to understand this.

Example: Suppose a manufacturing company stores the employee details in a table named employee
that has four attributes: emp_id for storing employee’s id, emp_name for storing employee’s name,
emp_address for storing employee’s address and emp_dept for storing the department details in which
the employee works. At some point of time the table looks like this:

Punjab University Sheikh Zayed Islamic Centre


Normalization 4

emp_id emp_name emp_address emp_dept

101 Rick Delhi D001

101 Rick Delhi D002

123 Maggie Agra D890

166 Glenn Chennai D900

166 Glenn Chennai D004

The above table is not normalized. We will see the problems that we face when a table is not
normalized.

Update anomaly: In the above table we have two rows for employee Rick as he belongs to two
departments of the company. If we want to update the address of Rick then we have to update the
same in two rows or the data will become inconsistent. If somehow, the correct address gets
updated in one department but not in other then as per the database, Rick would be having two
different addresses, which is not correct and would lead to inconsistent data.
Insert anomaly: Suppose a new employee joins the company, who is under training and currently
not assigned to any department then we would not be able to insert the data into the table if
emp_dept field doesn’t allow nulls.

Delete anomaly: Suppose, if at a point of time the company closes the department D890 then
deleting the rows that are having emp_dept as D890 would also delete the information of employee
Maggie since she is assigned only to this department.

To overcome these anomalies we need to normalize the data. In the next section we will
discuss about normalization.

Full Functional Dependencies


Identify the candidate keys (here, propertyNo, iDate and pAddress). This is because any
combination of those 3 can allow you to find what the other attributes are for a given tuple (I can find
the staffNo that did the inspection given those three things, I can find the carReg the staffNo used given
those 3 things etc.). But note, you need all of those 3 to find the other attributes, not just a
subset. Full dependencies always relate to non-candidate keys depending on candidate keys,
either depending on all or depending on some.

Punjab University Sheikh Zayed Islamic Centre


Normalization 5

Partial Dependencies
Given those three candidate keys, look within the candidate keys. Is there any subset(s) of the candidate
key which is dependent on the other? Yes, it is pAddress. Given a propertyNo, you can figure out what
the address of the property. Then look outside of the candidate keys. Is there any of these keys that
depend on only parts of the candidate key, not all components? In this case there are not. So partial
dependencies are always dependencies within the candidate keys or dependencies of non-
candidate keys on only parts of the candidate keys rather than all components

Transitive Dependencies
Now, look at the non-candidate keys (staffNo, comments, iTime (inspection time), sName, carReg).
Within those, is there anything that is functionally dependent on the other? Yes, it is sName - given a
staffNo, you can figure out the name of the staff member. But staffNo is functionally dependent on the
3 candidate keys. So by transitivity, propertyNo + iDate + pAddress -> staffNo -> sName, so sName is
transitively dependent on staffNo. Transitive dependencies always relate to attributes outside of
candidate keys.
share

Partial Dependency

A Composite Primary Key is a primary key that is made of multiple columns. It’s also often to hear the
term Candidate Key, which refers to the same thing.
Partial Dependency occurs when one of your non-key columns is functionally dependent on only a part
of the Composite Primary Key, and not the whole thing. Let’s look at an example.
Suppose we have a table with various fitness test results for different players.

player_id test_id points supervisor_name test_type


1 1 87/100 John Stewart 30m Sprint
1 3 56/100 Alicia Madison Vertical Jump Test
3 2 90/100 John Stewart One Rep Max
2 2 71/100 Isaiah Gray One Rep Max
The primary key in this case is a Composite Primary Key that is a made up of player_id and test_id.

Punjab University Sheikh Zayed Islamic Centre


Normalization 6
Both the points and the supervisor_name columns are directly dependent on the entire primary key
(player_id + test_id). The test_type column, on the other hand, is only dependent on test_id0 and has
nothing to do with player_id.
This is Partial Dependency. It happens when an attribute in a table depends only on a part of the
primary key and not on the whole key.

Why and how to fix it?


Partial Dependency leads to duplicate entries, and if we have a lot of duplicate entries in our tables, our
database will take up a lot more memory than it should. Partial Dependency, unless fixed, can also lead
to insertion, deletion and updation anomalies. What do these mean?
Say we had to insert a 100 new results into the table. Many players would do the same types of tests
(eg. One Rep Max), so this would lead to plenty of unnecessary duplicate entries in
the test_type column. This is a typical example of an insertion anomaly.
What would happen if we wanted to change the name of a single test type? For example, we want to
change the ’30m Sprint’ to the ’30m Dash’. Well, then you would have to find each row in the table that
contains ’30m Sprint’ entry and manually replace each one of those with ’30m Dash’. It is obviously a
lot of unnecessary hassle and we call this updation anomaly.
What if, for some reason, we decided to delete this entire table? Than, we would automatically delete
all the information about the different tests as well, which is not something we want. We want the
specific test type information to be completely standalone and independent of this table. We call this
problem a deletion anomaly.
But fortunately, it’s really easy to remove partial dependencies from your database. In this example, all
we have to do is split the original table into two new tables, like this.

player_id test_id points supervisor_name


1 1 87/100 John Stewart
1 3 56/100 Alicia Madison
3 2 90/100 John Stewart
2 2 71/100 Isaiah Gray

test_id test_type
1 30m Sprint
2 One Rep Max
3 Vertical Jump Test
4 Sit-up Test
Now the test_type column if fully dependent on the primary key of that table, and nothing else. By
splitting up the table we take care of all three already mentioned anomalies.
Transitive Dependency
Transitive Dependency occurs when you have a column that is functionally dependent on another
column that is not part of the primary key. Lets look at an example.
Say we had a table with information on each specific football player:
Punjab University Sheikh Zayed Islamic Centre
Normalization 7

player_id height weight club_id club_country


1 175 71 3 England
2 189 85 2 France
3 195 90 4 Germany
4 178 78 1 Italy
The columns height, weight and club_id are directly dependent on the primary key,
while club_country is not. club_country is only dependent on the club_id column, and not on the
primary key, which is player_id.
This is an example of transitive dependency. It occurs when a column is functionally dependent on
another column which is not a part of the primary key.
It’s really easy to take care of transitive dependency. All you have to do is split the original table into
two new tables, where each column of the tables will only be dependent only on the primary key of that
table.

player_id height weight club_id


1 175 71 3
2 189 85 2
3 195 90 4
4 178 78 1

club_id club_name club_country


1 Inter Italy
2 Nantes France
3 Liverpool England
4 Bayer Leverkusen Germany
The new club table only contains information on the different clubs. As you can see
here, club_country is now completely dependent on the club_id column, which is the primary key in
the new club table.
Just like with Partial Dependency, by doing this we take care of insertion, deletion and updation
anomalies. Also, by reducing the amount of duplicate entries, we reduce the amount of memory
required to store the database.
Partial and Transitive Dependencies need to be removed in order to have your database in the Second
and the Third Normal Form, respectively.

Punjab University Sheikh Zayed Islamic Centre


Normalization 8

Types of Normalization:
•First Normal Form (1NF)

•Second Normal Form (2NF)


•Third Normal Form (3NF)
•Boyce-Codd Normal Form (BCNF)
•Fourth Normal Form (4NF)
•Fifth Normal Form (5NF)

First normal form (1NF)


As per the rule of first normal form, an attribute (column) of a table cannot hold multiple values. It
should hold only atomic values.

Example: Suppose a company wants to store the names and contact details of its employees. It
creates a table that looks like this:

emp_id emp_name emp_address emp_mobile

101 Herschel New Delhi 8912312390

8812121212
102 Jon Kanpur 9900012222

103 Ron Chennai 7778881212

9990000123
104 Lester Bangalore 8123450987

Two employees (Jon & Lester) are having two mobile numbers so the company stored them in the
same field as you can see in the table above.
Punjab University Sheikh Zayed Islamic Centre
Normalization 9
This table is not in 1NF as the rule says “each attribute of a table must have atomic (single)
values”, the emp_mobile values for employees Jon & Lester violates that rule.

To make the table complies with 1NF we should have the data like this:

emp_id emp_name emp_address emp_mobile

101 Herschel New Delhi 8912312390

102 Jon Kanpur 8812121212

102 Jon Kanpur 9900012222

103 Ron Chennai 7778881212

104 Lester Bangalore 9990000123

104 Lester Bangalore 8123450987

Second normal form (2NF)


A table is said to be in 2NF if both the following conditions hold:

•Table is in 1NF (First normal form)

•No non-prime attribute is dependent on the proper subset of any candidate key of table.

An attribute that is not part of any candidate key is known as non-prime attribute.

Example: Suppose a school wants to store the data of teachers and the subjects they teach. They
create a table that looks like this: Since a teacher can teach more than one subjects, the table can
have multiple rows for a same teacher.

teacher_id subject teacher_age

111 Maths 38

111 Physics 38

222 Biology 38

333 Physics 40

333 Chemistry 40

Punjab University Sheikh Zayed Islamic Centre


Normalization 10
Candidate Keys: {teacher_id, subject}
Non prime attribute: teacher_age
The table is in 1 NF because each attribute has atomic values. However, it is not in 2NF because
non prime attribute teacher_age is dependent on teacher_id alone which is a proper subset of
candidate key. This violates the rule for 2NF as the rule says “no non-prime attribute is dependent
on the proper subset of any candidate key of the table”.

To make the table complies with 2NF we can break it in two tables like this:
teacher_details table:

teacher_id teacher_age

111 38

222 38

333 40
teacher_subject table:

teacher_id subject

111 Maths

111 Physics

222 Biology

333 Physics

333 Chemistry
Now the tables comply with Second normal form (2NF).

Third Normal form (3NF)


A table design is said to be in 3NF if both the following conditions hold:

•Table must be in 2NF

•Transitive functional dependency of non-prime attribute on any super key should be


removed.

An attribute that is not part of any candidate key is known as non-prime attribute.

Punjab University Sheikh Zayed Islamic Centre


Normalization 11
In other words 3NF can be explained like this: A table is in 3NF if it is in 2NF and for each
functional dependency X-> Y at least one of the following conditions hold:

•X is a super key of table

•Y is a prime attribute of table

An attribute that is a part of one of the candidate keys is known as prime attribute.

Example: Suppose a company wants to store the complete address of each employee, they create a
table named employee_details that looks like this:

emp_id emp_name emp_zip emp_state emp_city emp_district

1001 John 282005 UP Agra Dayal Bagh

1002 Ajeet 222008 TN Chennai M-City

1006 Lora 282007 TN Chennai Urrapakkam

1101 Lilly 292008 UK Pauri Bhagwan

1201 Steve 222999 MP Gwalior Ratan

Super keys: {emp_id}, {emp_id, emp_name}, {emp_id, emp_name, emp_zip}…so on


Candidate Keys: {emp_id}
Non-prime attributes: all attributes except emp_id are non-prime as they are not part of any
candidate keys.

Here, emp_state, emp_city & emp_district dependent on emp_zip. And, emp_zip is dependent on
emp_id that makes non-prime attributes (emp_state, emp_city & emp_district) transitively
dependent on super key (emp_id). This violates the rule of 3NF.

To make this table complies with 3NF we have to break the table into two tables to remove the
transitive dependency:

employee table:

emp_id emp_name emp_zip

1001 John 282005

Punjab University Sheikh Zayed Islamic Centre


Normalization 12

1002 Ajeet 222008

1006 Lora 282007

1101 Lilly 292008

1201 Steve 222999


employee_zip table:

emp_zip emp_state emp_city emp_district

282005 UP Agra Dayal Bagh

222008 TN Chennai M-City

282007 TN Chennai Urrapakkam

292008 UK Pauri Bhagwan

222999 MP Gwalior Ratan

Boyce Codd normal form (BCNF)


It is an advance version of 3NF that’s why it is also referred as 3.5NF. BCNF is stricter than 3NF. A
table complies with BCNF if it is in 3NF and for every functional dependency X->Y, X should be
the super key of the table.

Example: Suppose there is a company wherein employees work in more than one department.
They store the data like this:

emp_id emp_nationality emp_dept dept_type dept_no_of_emp

1001 Austrian Production and planning D001 200

1001 Austrian stores D001 250

1002 American design and technical support D134 100

1002 American Purchasing department D134 600

Functional dependencies in the table above:


emp_id -> emp_nationality
emp_dept -> {dept_type, dept_no_of_emp}
Candidate key: {emp_id, emp_dept}

Punjab University Sheikh Zayed Islamic Centre


Normalization 13
The table is not in BCNF as neither emp_id nor emp_dept alone are keys.

To make the table comply with BCNF we can break the table in three tables like this:

emp_nationality table:
emp_id emp_nationality

1001 Austrian

1002 American
emp_dept table:

emp_dept dept_type dept_no_of_emp

Production and planning D001 200

stores D001 250

design and technical support D134 100

Purchasing department D134 600


emp_dept_mapping table:

emp_id emp_dept

1001 Production and planning

1001 stores

1002 design and technical support

1002 Purchasing department


Functional dependencies:
emp_id -> emp_nationality
emp_dept -> {dept_type, dept_no_of_emp}

Candidate keys:
For first table: emp_id
For second table: emp_dept
For third table: {emp_id, emp_dept}

This is now in BCNF as in both the functional dependencies left side part is a key.

Punjab University Sheikh Zayed Islamic Centre


Normalization 14

References
➢https://www.webopedia.com/TERM/N/normalization.html
➢https://www.youtube.com/watch?v=PyZhvyCl3NY
➢https://stackoverflow.com/questions/16152167/normalization-
dependencies
➢https://iandzy.com/partial-transitive-dependency/
➢https://beginnersbook.com/2015/05/normalization-in-dbms/
➢https://www.assignmenthelp4me.com/assignment-answer-
normalization-assignment-help-26.html
➢https://www.w3schools.in/dbms/database-normalization/#fifth-normal-
form

Punjab University Sheikh Zayed Islamic Centre

You might also like