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

normalization-dbms

Normalization in databases is the process of reducing data redundancy and improving data integrity, addressing issues like insertion, update, and deletion anomalies. It involves organizing data into smaller tables and ensuring proper dependencies through various normal forms (1NF, 2NF, 3NF, BCNF, etc.). Each normal form has specific requirements to minimize redundancy and maintain data integrity in relational databases.

Uploaded by

Vansh negi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

normalization-dbms

Normalization in databases is the process of reducing data redundancy and improving data integrity, addressing issues like insertion, update, and deletion anomalies. It involves organizing data into smaller tables and ensuring proper dependencies through various normal forms (1NF, 2NF, 3NF, BCNF, etc.). Each normal form has specific requirements to minimize redundancy and maintain data integrity in relational databases.

Uploaded by

Vansh negi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

lOMoARcPSD|42736668

Normalization - dbms

Computer science engineering ( Haldia Institute of Technology)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by VANSH NEGGI CS-2022-26 ([email protected])
lOMoARcPSD|42736668

Normalization
What is Normalization in a Database?

It is the processes of reducing the redundancy of data in the table and also improving the data
integrity. So why is this required? without Normalization in SQL, we may face many issues
such as

1. Insertion anomaly: It occurs when we cannot insert data to the table without the
presence of another attribute
2. Update anomaly: It is a data inconsistency that results from data redundancy and a
partial update of data.
3. Deletion Anomaly: It occurs when certain attributes are lost because of the deletion of
other attributes.

Name Roll Stream Batch

AA 01 MCA 1

BB 02 EI 1

CC 03 EI 2

EE 03 EI 2

In brief, normalization is a way of organizing the data in the database. Normalization entails
organizing the columns and tables of a database to ensure that their dependencies are properly
enforced by database integrity constraints.

It usually divides a large table into smaller ones, so it is more efficient. In 1970 the First
Normal Form was defined by Edgar F Codd and eventually, other Normal Forms were
defined.

One question that arises in between is, what does SQL have to do with Normalization.
Well SQL is the language that is used to interact with the database. To initiate any interaction
the data present in the database has to be of Normalized Form. Else we cannot proceed
further as it results in anomalies.

Normalization in SQL will enhance the distribution of data. Now let’s understand each and
every Normal Form with examples.

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

Types of Normal Forms


There are the four 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.

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

5NF A relation is in 5NF if it is in 4NF and not contains any join dependency and joining

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

should be lossless.

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:

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

Second Normal Form (2NF)


o In the 2NF, relational must be in 1NF.

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

o In the second normal form, all non-key attributes are fully functional dependent on the
primary key

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

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:

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

83 Math

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

83 Computer

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.

Example:

EMPLOYEE_DETAIL table:

EMP_ID EMP_NAM EMP_ZIP EMP_STATE EMP_CITY


E

222 Harry 201010 UP Noida

333 Stephan 02228 US Boston

444 Lan 60007 US Chicago

555 Katharine 06389 UK Norwich

666 John 462007 MP Bhopal

Super key in the table above:

1. {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.

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

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

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.

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

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}10 SecCompetitivquestions on Structures

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:

EMP_ID EMP_COUNTRY

264 India

364 UK

EMP_DEPT table:

EMP_DEPT DEPT_TYPE EMP_DEPT_NO

Designing D394 283

Testing D394 300

Stores D283 232

Developing D283 549

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

EMP_DEPT_MAPPING table:

EMP_ID EMP_DEPT

D394 283

D394 300

D283 232

D283 549

Functional dependencies:

1. EMP_ID → EMP_COUNTRY
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.

Normalization with another example


First Normal Form
First Normal Form is defined in the definition of relations (tables) itself. This rule defines
that all the attributes in a relation must have atomic domains. The values in an atomic
domain are indivisible units.

We re-arrange the relation (table) as below, to convert it to First Normal Form.

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

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

Second Normal Form


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.
If we follow second normal form, then every non-prime attribute should be fully
functionally dependent on prime key attribute. That is, if X → A holds, then there should not
be any proper subset Y of X, for which Y → A also holds true.

We see here in Student_Project relation that the prime key attributes are Stu_ID and
Proj_ID. According to the rule, non-key attributes, i.e. Stu_Name and Proj_Name must be
dependent upon both and not on any of the prime key attribute individually. But we find that
Stu_Name can be identified by Stu_ID and Proj_Name can be identified by Proj_ID
independently. This is called partial dependency, which is not allowed in Second Normal
Form.

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

We broke the relation in two as depicted in the above picture. So there exists no partial
dependency.

Third Normal Form


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 −
o X is a superkey or,
o A is prime attribute.

We find that in the above Student_detail relation, Stu_ID is the key and only prime key
attribute. We find that City can be identified by Stu_ID as well as Zip itself. Neither Zip is a
superkey nor is City a prime attribute. Additionally, Stu_ID → Zip → City, so there
exists transitive dependency.
To bring this relation into third normal form, we break the relation into two relations as
follows −

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

Boyce-Codd Normal Form


Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms.
BCNF states that −

 For any non-trivial functional dependency, X → A, X must be a super-key.


In the above image, Stu_ID is the super-key in the relation Student_Detail and Zip is the
super-key in the relation ZipCodes. So,
Stu_ID → Stu_Name, Zip
and
Zip → City
Which confirms that both the relations are in BCNF.
Multivalue dependency occurs when the presence of one or more rows in a table
implies the presence of one or more other rows in that same table. Put another way, two
attributes (or columns) in a table are independent of one another, but both depend on a third
attribute. A multivalued dependency always requires at least three attributes because it
consists of at least two attributes that are dependent on a third.
For a dependency A -> B, if for a single value of A, multiple value of B exists, then the
table may have multi-valued dependency. The table should have at least 3 attributes and B
and C should be independent for A ->> B multivalued dependency. For example,

Person Mobile Food_Likes

Mahesh 9893/9424 Burger / pizza

Ramesh 9191 Pizza

Person->-> mobile,
Person ->-> food_likes
This is read as “person multidetermines mobile” and “person multidetermines food_likes.”
Note that a functional dependency is a special case of multivalued dependency. In a
functional dependency X -> Y, every x determines exactly one y, never more than one.

Multivalued Dependency
o Multivalued dependency occurs when two attributes in a table are
independent of each other but, both depend on a third attribute.
o A multivalued dependency consists of at least two attributes that
are dependent on a third attribute that's why it always requires at
least three attributes.

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

Example: Suppose there is a bike manufacturer company which produces


two colors(white and black) of each model every year.

BIKE_MODEL MANUF_YEAR COLOR

M2011 2008 White

M2001 2008 Black

M3001 2013 White

M3001 2013 Black

M4006 2017 White

M4006 2017 Black

Here columns COLOR and MANUF_YEAR are dependent on BIKE_MODEL


and independent of each other.

In this case, these two columns can be called as multivalued dependent


on BIKE_MODEL. The representation of these dependencies is shown
below:

1. BIKE_MODEL → → MANUF_YEAR
2. BIKE_MODEL → → COLOR

This can be read as "BIKE_MODEL multidetermined MANUF_YEAR" and


"BIKE_MODEL multidetermined COLOR".

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

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

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.

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

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

Example 2
Example – Consider the database table of a class whaich has two relations R1 contains
student ID(SID) and student name (SNAME) and R2 contains course id(CID) and course
name (CNAME).

Table – R1(SID, SNAME)


SID SNAME

S1 A

S2 B

Table – R2(CID, CNAME)


CID CNAME

C1 C

C2 D

When there cross product is done it resulted in multivalued dependencies:

Table – R1 X R2
SID SNAME CID CNAME

S1 A C1 C

S1 A C2 D

S2 B C1 C

S2 B C2 D

Multivalued dependencies (MVD) are:


SID->->CID; SID->->CNAME; SNAME->->CNAME
Joint dependency – Join decomposition is a further generalization of Multivalued
dependencies. If the join of R1 and R2 over C is equal to relation R then we can say that a
join dependency (JD) exists, where R1 and R2 are the decomposition R1(A, B, C) and
R2(C, D) of a given relations R (A, B, C, D). Alternatively, R1 and R2 are a lossless

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

decomposition of R. A JD ⋈ {R1, R2, …, Rn} is said to hold over a relation R if R1, R2,
….., Rn is a lossless-join decomposition. The *(A, B, C, D), (C, D) will be a JD of R if the
join of join’s attribute is equal to the relation R. Here, *(R1, R2, R3) is used to indicate that
relation R1, R2, R3 and so on are a JD of R.
Let R is a relation schema R1, R2, R3……..Rn be the decomposition of R. r( R ) is said to
satisfy join dependency if and only if
Example –

Company Product

C1 pendrive

C1 mic

C2 speaker

C2 speaker
Company->->Product

Table – R2
Agent Company

Aman C1

Aman C2

Mohan C1
Agent->->Company

Table – R3
Agent Product

Aman pendrive

Aman mic

Aman speaker

Mohan speaker

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

Agent->->Product

Table – R1⋈R2⋈R3
Company Product Agent

C1 pendrive Aman

C1 mic Aman

C2 speaker speaker

C1 speaker Aman
Agent->->Product
Fifth Normal Form / Projected Normal Form (5NF):
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
Agent Company Product

A1 PQR Nut

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

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

Agent Company

A1 PQR

A1 XYZ

A2 PQR

Table – R2
Agent Product

A1 Nut

A1 Bolt

A2 Nut

Table – R3
Company 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.

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.

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

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

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

SUBJECT LECTURER

Computer Anshika

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])


lOMoARcPSD|42736668

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

Downloaded by VANSH NEGGI CS-2022-26 ([email protected])

You might also like