0% found this document useful (0 votes)
11 views

Unit4

Normalization in DBMS is a process aimed at organizing data to eliminate redundancy and various anomalies such as insertion, update, and deletion anomalies. The document outlines the different normal forms (1NF, 2NF, 3NF, and BCNF) and explains functional dependencies, including fully functional, partial, trivial, and non-trivial dependencies. It provides examples and explanations of how to achieve normalization to improve database design and integrity.

Uploaded by

gowtami
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)
11 views

Unit4

Normalization in DBMS is a process aimed at organizing data to eliminate redundancy and various anomalies such as insertion, update, and deletion anomalies. The document outlines the different normal forms (1NF, 2NF, 3NF, and BCNF) and explains functional dependencies, including fully functional, partial, trivial, and non-trivial dependencies. It provides examples and explanations of how to achieve normalization to improve database design and integrity.

Uploaded by

gowtami
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/ 25

NORMALIZATION

Normalization in DBMS: 1NF,


2NF, 3NF and BCNF in Database
Normalization is a process of organizing the data in database to avoid data
redundancy, insertion anomaly, update anomaly & deletion anomaly.

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.

emp_id emp_name emp_address emp_dept

101 Rick Delhi D001

Delhi

101 Rick D002

123 Maggie Agra D890

166 Glenn Chennai D900

166 Glenn Chennai D004


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 thi

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.

Functional Dependency:

In Relational database, A functional dependency is a constraint that


specifies the relationship between two sets of attributes where one set can
accurately determine the value of other sets

Functional dependency is denoted as


 X -> Y
 X: Determinant
 Y: Dependent

 Functional dependencies are used to mathematically express relations


among database entities
 Example:

roll_n
o name dept_name dept_building

42 abc CO A4

43 pqr IT A3

44 xyz CO A4

45 xyz IT A3

46 mno EC B2

47 jkl ME B2

 roll_no → { name, dept_name, dept_building },→ Here, roll_no can


determine values of fields name, dept_name and dept_building, hence a
valid Functional dependency
 roll_no → dept_name , Since, roll_no can determine whole set of {name,
dept_name, dept_building}, it can determine its subset dept_name also.
 dept_name → dept_building , Dept_name can identify the dept_building
accurately, since departments with different dept_name will also have a
different dept_building
 More valid functional dependencies: roll_no → name, {roll_no, name} ⇢
{dept_name, dept_building}, etc.
Here are some invalid functional dependencies:
 name → dept_name Students with the same name can have different
dept_name, hence this is not a valid functional dependency.
 dept_building → dept_name There can be multiple departments in the
same building, For example, in the above table departments ME and EC
are in the same building B2, hence dept_building → dept_name is an
invalid functional dependency.
 More invalid functional dependencies: name → roll_no, {name,
dept_name} → roll_no, dept_building → roll_no, etc

Types of Functional Dependencies

1.Fully Functional Dependency

If X and Y are an attribute set of a relation, Y is fully functional dependent on


X, if Y is functionally dependent on X but not on any proper subset of
X.

Example –
In the relation ABC->D, attribute D is fully functionally dependent on
ABC and not on any proper subset of ABC. That means that subsets
of ABC like AB, BC, A, B, etc cannot determine D.

Supply table
supplier_i
item_id price
d

1 1 540

2 1 545

1 2 200

2 2 201

1 1 540

2 2 201

3 1 542

From the table, we can clearly see that neither supplier_id nor item_id can
uniquely determine the price but both supplier_id and item_id together can
do so. So we can say that price is fully functionally dependent on
{ supplier_id, item_id }. This summarizes and gives our fully functional
dependency −
{ supplier_id , item_id } -> price
Partial Functional Dependency :
A functional dependency X->Y is a partial dependency if Y is
functionally dependent on X and Y can be determined by any proper
subset of X.
For example, we have a relationship AC->B, A->D, and D->B.
Now if we compute the closure of {A +}=ADB
Here A is alone capable of determining B, which means B is partially
dependent on AC.

Student table
Name roll_no Course

Ravi 2 DBMS

Tim 3 OS

John 5 Java

Here, we can see that both the attributes name and roll_no alone are able to
uniquely identify a course. Hence we can say that the relationship is partially
dependent.

Trivial functional dependency


o A → B has trivial functional dependency if B is a subset of A.
o The following dependencies are also trivial like: A → A, B → B

Example:

1. Consider a table with two columns Employee_Id and Employee_Name.


2. {Employee_id, Employee_Name} → Employee_Id is a trivial functional depend
ency as
3. Employee_Id is a subset of {Employee_Id, Employee_Name}.
4. Also, Employee_Id → Employee_Id and Employee_Name → Employee_Name ar
e trivial dependencies too.
. Non-trivial functional dependency
o A → B has a non-trivial functional dependency if B is not a subset of A.
o When A intersection B is NULL, then A → B is called as complete non-
trivial.

Example:

1. ID → Name,
2. Name → DOB

Transitive Dependency in DBMS


A Transitive Dependency is a type of functional dependency which
happens when “t” is indirectly formed by two functional dependencies.

Example:

Company CEO Age


Microsoft Satya Nadella 51
Google Sundar Pichai 46
Alibaba Jack Ma 54
{Company} -> {CEO} (if we know the compay, we know its CEO’s name)

{CEO } -> {Age} If we know the CEO, we know the Age

Therefore according to the rule of rule of transitive dependency:

{ Company} -> {Age}

Multivalued Dependency in DBMS


Multivalued dependency occurs in the situation where there are multiple
independent multivalued attributes in a single table. A multivalued
dependency is a complete constraint between two sets of attributes in a
relation. It requires that certain tuples be present in a relation.

Example:
Car_model Maf_year Color
H001 2017 Metallic
H001 2017 Green
H005 2018 Metallic
H005 2018 Blue
H010 2015 Metallic
Car_model Maf_year Color
H033 2012 Gray
In this example, maf_year and color are independent of each other but
dependent on car_model. In this example, these two columns are said to
be multivalue dependent on car_model.

This dependence can be represented like this:

car_model ->-> maf_year

car_model->-> colour

Normalization
Here are the most commonly used normal forms:

 First normal form(1NF)


 Second normal form(2NF)
 Third normal form(3NF)
 Boyce & Codd normal form (BCNF)
 Fourth Normal form

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.

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

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

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.

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.
teacher_id Subject teacher_age

111 Maths 38

111 Physics 38

222 Biology 38

333 Physics 40

333 Chemistry 40

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.

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.

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_i emp_na emp_ziemp_sta emp_ci emp_distri

d me p te ty ct

1001 John 28200 UP Agra Dayal


5 Bagh

22200 Chenn
1002 Ajeet TN M-City
8 ai

28200 Chenn Urrapakka


1006 Lora TN
7 ai m

29200
1101 Lilly UK Pauri Bhagwan
8

22299
1201 Steve MP GwaliorRatan
9

emp_id emp_name emp_zip

1001 John 282005

1002 Ajeet 222008

1006 Lora 282007


1101 Lilly 292008

1201 Steve 222999

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:

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:

Student Teacher Subject

Jhansi P.Naresh Database

Jhansi K.Das C

Subbu P.Naresh Database

Subbu R.Prasad C

F: { (student, Teacher) -> subject


(student, subject) -> Teacher
Teacher -> subject}
Candidate keys are (student, teacher) and (student, subject).
The above relation is in 3NF [since there is no transitive dependency]. A relation R
is in BCNF if for every non-trivial FD X->Y, X must be a key.
The above relation is not in BCNF, because in the FD (teacher->subject), teacher is
not a key. This relation suffers with anomalies −
For example, if we try to delete the student Subbu, we will lose the information that
R. Prasad teaches C. These difficulties are caused by the fact the teacher is
determinant but not a candidate key.

Decomposition for BCNF


Teacher-> subject violates BCNF [since teacher is not a candidate key].
If X->Y violates BCNF then divide R into R1(X, Y) and R2(R-Y).
So R is divided into two relations R1(Teacher, subject) and R2(student, Teacher).
R1

Teacher Subject

P.Naresh Database

K.DAS C

R.Prasad C

R2

Student Teacher

Jhansi P.Naresh

Jhansi K.Das

Subbu P.Naresh

Subbu R.Prasad

emp_idemp_nationalityemp_dept dept_typedept_no_of_emp
1001 Austrian Production and planning D001 200

1001 Austrian Stores D001 250

design and technical


1002 American D134 100
support

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}

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

emp_id emp_nationality

1001 Austrian

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

emp_nationality 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 table:
emp_id emp_dept

1001 Production and planning

1001 Stores

1002 design and technical support

1002 Purchasing department

emp_dept_mapping table:

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.

Difference between 3NF and BCNF :


S.NO
. 3NF BCNF

BCNF stands for Boyce Codd


1. 3NF stands for Third Normal Form.
Normal Form.

In 3NF there should be no transitive


dependency that is no non prime attribute In BCNF for any relation A->B, A
2.
should be transitively dependent on the should be a super key of relation.
candidate key.

It is comparatively more stronger


3. It is less stronger than BCNF.
than 3NF.

In BCNF the functional


In 3NF the functional dependencies are
4. dependencies are already in 1NF,
already in 1NF and 2NF.
2NF and 3NF.

The redundancy is comparatively


5. The redundancy is high in 3NF.
low in BCNF.

In BCNF there may or may not be


In 3NF there is preservation of all
6. preservation of all functional
functional dependencies.
dependencies.

7. It is comparatively easier to achieve. It is difficult to achieve.

Lossless decomposition can be achieved Lossless decomposition is hard to


8.
by 3NF. achieve in BCNF.

The table is in 3NF if it is in 2NF and for


each functional dependency X->Y at least
following condition hold: The table is in BCNF if it is in 3rd
9. normal form and for each relation
(i) X is a super key, X->Y X should be super key.
(ii) Y is prime attribute of table.

3NF can be obtained without sacrificing Dependencies may not be


10.
all dependencies. preserved in BCNF.

11. 3NF can be achieved without losing any For obtaining BCNF we may lose
S.NO
. 3NF BCNF

information from the old table. some information from old table.

5NF(Fifth Normal Form)

A relation R is in 5NF if and only if every join dependency in R is implied by


the candidate keys of R. A relation decomposed into two relations must have
loss-less join Property, which ensures that no spurious or extra tuples are
generated, when relations are reunited through a natural join.
Properties – A relation R is in 5NF if and only if it satisfies following
conditions:

1. R should be already in 4NF.

2. It cannot be further non loss decomposed (join dependency)


Example – Consider the above schema, with a case as “if a company makes
a product and an agent is an agent for that company, then he always sells
that product for the company”. Under these circumstances, the ACP table is
shown as:

Table – ACP

Agen
t Company Product

A1 PQR Nut
Agen
t Company Product

A1 PQR Bolt

A1 XYZ Nut

A1 XYZ Bolt

A2 PQR Nut

The relation ACP is again decompose into 3 relations. Now, the natural Join
of all the three relations will be shown as:
Table – R1

Agen
t Company

A1 PQR

A1 XYZ

A2 PQR

Table – R2

Agent Product

A1 Nut
Agent Product

A1 Bolt

A2 Nut

Table – R3

Compan
y Product

PQR Nut

PQR Bolt

XYZ Nut

XYZ Bolt

Result of Natural Join of R1 and R3 over ‘Company’ and then Natural Join of
R13 and R2 over ‘Agent’and ‘Product’ will be table ACP.

Hence, in this example, all the redundancies are eliminated, and the
decomposition of ACP is a lossless join decomposition. Therefore, the
relation is in 5NF as it does not violate the property of lossless join.

Surrogate Key

A surrogate key in DBMS is the key or can say a unique identifier that
uniquely identifies an object or an entity in their respective fields. It is the
unique identifier in a database.

we do not have a natural primary key in a table, then we need to artificially


create one in order to uniquely identify a row in the table , this key is called
the surrogate key or synthetic primary key of the table. However , surrogate
key is not always the primary key
Features of the surrogate key :
 It is automatically generated by the system.
 It holds anonymous integer.
 It contains unique value for all records of the table.
 The value can never be modified by the user or application.
 Surrogate key is called the factless key as it is added just for our ease of
identification of unique values and contains no relevant fact(or
information) that is useful for the table.

Consider an example :
Suppose we have two tables of two different schools having the same
column registration_no , name and percentage , each table having its own
natural primary key, that is registration_no.
Table of school A –

registration_no name percentage

210101 Harry 90

210102 Maxwell 65

210103 Lee 87

210104 Chris 76

Table of school B –

registration_n
name percentage
o

CS107 Taylor 49

CS108 Simon 86

CS109 Sam 96

CS110 Andy 58

Now, suppose we want to merge the details of both the schools in a single
table .
Resulting table will be –

surr_no registration_no name percentage


1 210101 Harry 90

2 210102 Maxwell 65

3 210103 Lee 87

4 210104 Chris 76

5 CS107 Taylor 49

6 CS108 Simon 86

7 CS109 Sam 96

8 CS110 Andy 58

As we can observe the above table and see that registration_no cannot be
the primary key of the table as it does not match with all the records of the
table though it is holding all unique values of the table . Now , in this case,
we have to artificially create one primary key for this table. We can do this by
adding a column surr_no in the table that contains anonymous integers and
has no direct relation with other columns . This additional column of surr_no
is the surrogate key of the table.
Advantages of the surrogate key :
 As there is no direct information related with the table, so the changes are
only based on the requirements of the application.
 Performance is enhanced as the value of the key is relatively smaller.
 The key value is guaranteed to contain unique information .
 As it holds smaller constant values , this makes integration of the table
easy .
 Enables us to run fast queries (as compared to the natural primary key)
Disadvantages of the surrogate key :
 The surrogate key value can never be used as a search key.
 As the key value has no relation to the data of the table, so third normal
form is violated.
 The extra column for surrogate key will require extra disk space.
 We will need extra IO when we have to insert or update data of the table.
Some examples of Surrogate key are :
 System date & time stamp
 Random alphanumeric string

You might also like