Anomalies in Database

Anomaly is a fault which occurs in the poorly designed database , which leads to inconsistent, redundant and inefficient data.

There are three kind of anomalies:

- Insertion anomaly

- Updation anomaly

- Deletion anomaly

Insertion Anomaly

It occurs when we want to insert a particular kind of data, let's say Data#1, but due to the absence of a certain data, let's say Data#2, we were unable to add.

Example

If we have only one table for saving student and course, named std_course.

We won't be able to add the new course until, we have the student information.


std_course Table 

Student_ID Student_Name Course Instructor Instructor_Contact
101 Ali DBMS Mr. Khan 123456789
102 Ahmed OS Mr. Ahsan 987654321

Suppose a new course "Computer Networks" is introduced.

But we cannot insert it into this table unless at least one student is enrolled.

Issue: Course information is dependent on students.

Problem: Unnecessary dependency forces inserting unrelated data.

How to Fix?

Normalize the database and separate Courses and Students into different tables.

Course Table

Course_ID Course_Name Instructor Instructor_Contact
C101 DBMS Mr. Khan 123456789
C102 OS Mr. Ahsan 987654321
C103 Computer Networks Mr. Rehman 555444333

Students Table

Student_ID Student_Name
101 Ali
102 Ahmed

Student_Course Table (Mapping)

Student_ID Course_ID
101 C101
102 C102

Comments

Popular posts from this blog

Kubernetes terms made easy