Skip to main content

Anomalies in Database Manipulation

 

Normalization in database design is a process used to organize data to reduce redundancy and improve data integrity.

It involves dividing a database into multiple tables and define relationship between them.

There are several types of anomalies that can arise when a database is not normalized.

The three main types of normalization anomalies.

1.      Insertion anomaly

An insertion anomaly normally occurs when you can’t insert data into the database without the presence of other data.

 

Students

StudId

StuName

Course

Instructor

1

Jack

Math

Prof. Raghu

2

Jim

Science

Prof. Radha

3

Harry

Computer Science

Prof. Venkat

4

Henry

Digital Marketing

Prof. Jasmine

5

Rose

Finance

Ms. Smith

 

The college/Institute decides to start a new course – “Java Full Stack” – there are no students enrolled in this new course

We can’t insert the new course details into the above table because there are no students enrolled and without PK value we can’t insert data into students table. We need to normalize the table.

So, we divide the above table into two different connected tables.

 

Courses

CourseId

Course

Instructor

C100

Math

Prof. Raghu

C101

Science

Prof. Radha

C102

Computer Science

Prof. Venkat

C103

Digital Marketing

Prof. Jasmine

C104

Finance

Ms. Smith

C105

Java Full Stack

Ms. Rani

 

Students

StudId

StuName

CourseId

1

Jack

C100

2

Jim

C101

3

Harry

C102

4

Henry

C103

5

Rose

C104

 

CourseId in Students table is the FK referring to PK of Courses table.

 

2.      Update Anomaly

An update anomaly occurs when changes to data in one place requires changes to be made in multiple places

Students

StudId

StuName

Course

Instructor

1

Jack

Math

Prof. Raghu

2

Jim

Science

Prof. Radha

3

Henry

Computer Science

Prof. Venkat

4

Henry

Digital Marketing

Prof. Jasmine

5

Jack

Finance

Ms. Smith

 

Let’s say the Course of Jack changes to something else. Since there are multiple entries in the students table it causes anomalies if we incorrectly or incompletely update. Normalize the table to solve the anomaly.

3.      Delete anomaly

A delete anomaly occurs when deleting data inadequately deletes/removing other important data.

 

Students

StudId

StuName

Course

Instructor

1

Jack

Math

Prof. Raghu

2

Jim

Science

Prof. Radha

3

Henry

Computer Science

Prof. Venkat

4

Henry

Digital Marketing

Prof. Jasmine

5

Jack

Finance

Ms. Smith

 

Let’s say the student named Jim is leaving the college due to some reason. If we delete the details of Student Jim we lose the data related to the Science course and its instructor.

To solve this break, it in to two tables Courses and Students.

 

 

Normalization Summary

Type of Normalization

Rules

First Normal Form – 1NF

1.      All columns contain atomic values (indivisible/single values) – no multi valued columns

2.      Each column contains values of same type

3.      Each column must have a unique name

4.      The order in which data is stored doesn’t matter.

 

Second Normal Form – 2NF

1.      The table must already be in 1NF i.e. there must be no non atomic values

2.      All non-key attributes must be fully dependent on primary key – there should be no partial dependency

 

Third Normal Form – 3NF

1.      The table must be in 2NF already

2.      No transitive dependency exists. Non key attributes must depend only on the primary key. The non key attributes must not depend on non-key columns.

 

BCNF – Boyce Codd Normal Form – 3.5NF

1.     The first condition is the table should already be in 3NF

2.      It aims to minimise redundancy further by ensuring that non key attributes depend only on the primary key and other non-key attributes

Fourth Normal Form – 4NF

1.      It is in BCNF already

2.      It contains no multivalued dependencies, meaning that one attribute in a table can determine multiple values of another attribute independently of other attributes

 

Fifth Normal Form – 5NF

1.      It should already be in 4NF

2.      Every join dependency in the table is a consequence of candidate keys.

 

Comments

Popular posts from this blog

DBMS CHECKLIST

DBMS Types Data Independence Three schema architecture DBMS users Dr.E.F.Codd’s rules for RDBMS (0-12) ER Model SQL DDL – CREATE, ALTER, DROP, TRUNCATE, RENAME DML – INSERT, UPDATE, DELETE DCL – GRANT, REVOKE, CREATE USER, DROP USER TCL – COMMIT, ROLLBACK, SAVEPOINT DATATYPES, OPERATORS(ARITHMETIC,RELATIONAL) CONSTRAINTS (PRIMARY KEY, FOREIGN KEY, NOT NULL, UNIQUE, CHECK) WHERE CLAUSE ORDER BY ASC | DESC DISTINCT GROUP BY - HAVING FUNCTIONS 1.      SINGLE ROW FUNCTIONS(UPPER,LOWER,SUBSTR,INITCAP,LENGTH,TRIM,LTRIM,RTRIM) 2.      AGGREGATE FUNCTIONS(MIN,MAX,SUM,AVG,COUNT) 3.      NUMBER FUNCTIONS(ROUND,CEIL,FLOOR,ABS,MOD,SQRT,POWER) 4.      DATE FUNCTIONS(TO_DATE,ADD_MONTHS,TO_CHAR,NEXTDAY,MONTHS_BETWEEN, SYSDATE) 5.      NULL FUNCTIONS(NVL,NVL2,COALESCE) OPERATORS IN NOT IN BETWEEN AND IS NULL LIKE, NOT LIKE PATTERN MATCHING IS ...

Look before you Leap...

Hey there, Lets talk about Information. Many a times we are not the first hand recipients of information. We receive information from someone or through the Internet or the media. Some of us are wise enough to ponder over the details received from any third or fourth party sources but most of us blindly believe in what comes around from Mr.XYZ and everyone around. A wise one would use his/her intellect and wisdom to ponder over that information and decide whether to trust and take it in or throw it out. That is what makes us different from animals. The power of thinking and intellect. To illustrate this, lets remind ourselves of this famous story of a fox. There was once a fox in a jungle. One day the fox accidentally slipped in to a deep well and was unable to get out of there. So it came up with an idea. As soon as it heard a sheep bleat, it started exclaiming very loud  "wow. This water is so tasty!".  Hearing this the sheep went close to the well and asked...

Everything about computers

Hi, I am quite excited to start the technical part of my blog! I hope so are you! Let's start with the Abc of computers that we all find a bit hard to put in to words. These are my own definitions made really simple and easy to understand! Computer:   An electronic device that computes, stores, processes , manipulates and displays the data. Coined from the term "compute", means to calculate. Facts:  First ever computer was used for mathematical calculations. Founder: Charles Babbage - The Father of computers - invented the first ever mechanical computer called "Babbage's Analytical Engine"! Features of a Computer / Advantages of computer over a calculator: Speed, Accuracy, Storage, Multi tasking, Diligence (and many more). A computer comprises of Software and Hardware (all the physical - internal or external components/peripherals that are connected to or a part of computer ex. Keyboard, Mouse, Cabinet, Joystick, USB - pen drive etc. that we c...