Anomalies: Insert, Update & Delete
A badly designed table can be internally consistent today and impossible to update correctly tomorrow. Anomalies are the symptoms.
In plain English
It is writing the same fact in many places: change one copy and forget another, and the notebook disagrees with itself.
The one idea
Redundancy causes insert, update, and delete anomalies; normalization removes the cause, not just the repeated value.
Repeated facts drift apart. A database that disagrees with itself is worse than a database that is merely slow.
By the end
- 01Recognize insertion, update, and deletion anomalies.
- 02Explain redundancy in a denormalized table.
- 03Connect anomalies to functional dependencies.
- 04Know why normalization reduces anomalies.
The denormalized table
Consider Enrollment(student_id, student_name, course_id, course_name, instructor_id, instructor_name, grade). Student names repeat for every course, course names repeat for every student, and instructor names repeat for every course. The redundancy is the root cause of the anomalies.
student_id | student_name | course_id | course_name | instructor
1 | Ada | C1 | DBMS | I1
1 | Ada | C2 | OS | I2
2 | Grace | C1 | DBMS | I1Insertion anomaly
You cannot insert a new course without a student, because the table requires a student_id. You cannot insert a student without a course. The schema forces unrelated facts to be stored together.
Update and deletion anomalies
If the course name changes, every row for that course must be updated; missing one creates inconsistency. Deleting the last student in a course can erase the course and instructor information entirely. Normalization splits the facts into separate relations so each fact is stored once.
The advisor name repeated
Student rows store advisor_id and advisor_name. Dr. Hopper advises twenty students.
Rename Dr. Hopper in one row.
The same advisor now has two names in the same table.
Delete the last student advised by Dr. Turing.
The advisor disappears entirely, even though the advisor still exists.
Add a new advisor with no students yet.
There is no row in which to store the advisor without inventing a fake student.
ConclusionThe problem is not that the name is long. The problem is that one fact has many homes.
The trade-off
No free correctness.
Gain
One fact, one place, one update.
Cost
More relations and more joins at read time.
Verdict
Normalize operational data; denormalize deliberately in warehouses where the redundancy is controlled.
Recap
What to keep.
Takeaways
- +Insertion anomalies prevent storing independent facts.
- +Update anomalies cause inconsistent copies of the same fact.
- +Deletion anomalies erase unrelated facts.
- +Redundancy is the common cause.
- +Normalization stores each fact once.
Traps
- !Thinking anomalies only appear with duplicate rows; they can appear with no exact duplicate.
- !Denormalizing before understanding the workload.
- !Blaming the DBMS for a schema design problem.
Focus
- →Give one concrete insertion, update, and deletion anomaly.
- →Trace redundancy to a functional dependency.
- →Explain how decomposition removes the anomaly.
Check yourself
Before you turn the page.
What causes an update anomaly?
Which anomaly can erase unrelated facts?