1. Home
  2. Interview Questions
  3. SQL
  4. What are insertion, update and deletion anomalies, and how d…

Try answering first

In a real interview nobody shows you the answer. Think it through (or type it), then reveal the answers and rate yourself.

1 Answer

0 0
InterviewQuestions Team ✔ Expert answer ✔ Best answer ·

Short answer: Anomalies are data problems caused by storing unrelated facts in one table: you cannot insert one fact without another (insertion), must change the same fact in many rows (update), or lose a fact when deleting another (deletion). Normalization splits the table so each fact is stored once, in a table where it depends only on that table's key.

Detailed explanation

Anomalies are the practical reason normalization exists. Normal forms are rules, and anomalies are the bugs those rules prevent. Most anomalies come from redundancy. The same fact is repeated across many rows because it is stored alongside data it does not really depend on.

  • Insertion anomaly: you cannot record a fact unless some unrelated fact also exists. For example, you cannot add a new course until at least one student enrolls, because the key needs a student_id.
  • Update anomaly: one real-world fact is stored in many rows. Changing it means updating every copy. Miss one row and the database now contradicts itself.
  • Deletion anomaly: deleting one fact accidentally removes another. If the last student drops a course, the course's name and instructor disappear with that row.

Normalization removes these problems by decomposing the table. Each non-key column should depend on the key, the whole key, and nothing but the key. In practice:

  • 2NF removes partial dependencies, where a column depends on only part of a composite key.
  • 3NF removes transitive dependencies, where a non-key column depends on another non-key column.

After decomposition, each fact lives in exactly one row. Foreign keys link the tables back together, and joins rebuild the original view when needed.

Example

An unnormalized enrollment table with key (student_id, course_id):

enrollment(student_id, student_name, course_id, course_name,
           instructor, instructor_phone, grade)

-- course_name, instructor depend only on course_id      (partial dependency)
-- student_name depends only on student_id               (partial dependency)
-- instructor_phone depends on instructor, not the key   (transitive dependency)

The problems this design causes:

  • You cannot add course C105 before someone enrolls (insertion).
  • An instructor's phone number changes, and it must be updated in hundreds of rows (update).
  • The only student in C105 leaves, and the course details vanish (deletion).

The normalized design (3NF):

CREATE TABLE student (
  student_id   INT PRIMARY KEY,
  student_name VARCHAR(100) NOT NULL
);

CREATE TABLE instructor (
  instructor_id INT PRIMARY KEY,
  name          VARCHAR(100) NOT NULL,
  phone         VARCHAR(20)
);

CREATE TABLE course (
  course_id     VARCHAR(10) PRIMARY KEY,
  course_name   VARCHAR(100) NOT NULL,
  instructor_id INT REFERENCES instructor(instructor_id)
);

CREATE TABLE enrollment (
  student_id INT REFERENCES student(student_id),
  course_id  VARCHAR(10) REFERENCES course(course_id),
  grade      CHAR(2),
  PRIMARY KEY (student_id, course_id)
);

With this design:

  • A course can now exist with zero enrollments.
  • A phone number is stored once.
  • Deleting an enrollment never deletes course or instructor data.

Common mistakes

  • Defining anomalies only in theory. Interviewers expect a concrete table and a concrete broken scenario for each type.
  • Confusing an update anomaly with a slow update. The issue is inconsistency from missed copies, not performance.
  • Thinking normalization means splitting every column into its own table. Over-splitting adds joins without removing any redundancy.
  • Forgetting that denormalized reporting tables reintroduce these anomalies. They need a controlled refresh process, such as ETL jobs or materialized views.

Follow-up questions

  • Which normal form removes partial dependencies, and which removes transitive dependencies?
  • When would you deliberately denormalize, and how would you keep the redundant data consistent?
  • Can a table in 3NF still have anomalies?

Interview tip: Sketch one wide table and walk through all three anomalies on it before naming any normal form; it shows you understand the purpose, not just the definitions.

Reviewed by the Interview Questions editorial team · Last updated

How well did you know this?

Rate yourself to track progress, build your streak and get “didn't know” questions in your revision list.

Your Answer

More easy SQL questions

All easy questions →

Related Questions

‹
Q8 of 10 · SQL
Next ›

Interview Questions

Free interview questions and answers, MCQ practice, online tests, mock interviews and group discussions — everything you need to crack your next interview.
📍 Dasardot LLC
1309 Coffeen Avenue STE 1200
Sheridan, Wyoming 82801
USA