Difficulty: Beginner
Why is data redundancy considered bad in a relational database? Explain with the types of anomalies it causes.
Redundancy means storing the same fact in more than one place, and it is risky because those copies can drift apart. When one copy is updated and another is not, the database holds two contradictory answers to the same question. Redundancy also causes insert and delete anomalies and wastes storage, which is why normalization exists.
Imagine one table for college placements:
| student_id | student_name | company | company_city | package_lpa |
|---|---|---|---|---|
| 1 | Asha | Zoho | Chennai | 8 |
| 2 | Rohan | Zoho | Chennai | 8 |
| 3 | Meera | Razorpay | Bengaluru | 18 |
The fact "Zoho is in Chennai" is stored once per student placed there.
All three come from mixing two different entities (students and companies) in one table.
Split the table so each fact lives once:
companies(company_id, name, city)placements(student_id, company_id, package_lpa)Now the city is updated in one row, a company can exist with no placements, and deleting a placement leaves the company intact. This is what Second and Third Normal Form formalize: non-key attributes must depend on the whole key and only on the key.
Normalization is not an absolute rule. Teams intentionally denormalize when reads vastly outnumber writes or when joins become a bottleneck:
total_amount_paise on orders even though it can be computed from order_items.The rule of thumb: redundancy is acceptable when there is one clear source of truth and a reliable mechanism (trigger, transaction, event, scheduled refresh) that keeps copies consistent.
| Anomaly | What goes wrong | |
|---|---|---|
| Update | Change a duplicated value | Some copies updated, others stale |
| Insert | Add a company with no students | No valid row to store it in |
| Delete | Remove the last student at a company | Company details lost too |
CREATE TABLE companies (
company_id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
city TEXT NOT NULL
);
CREATE TABLE placements (
student_id BIGINT NOT NULL REFERENCES students(id),
company_id BIGINT NOT NULL REFERENCES companies(company_id),
package_lpa NUMERIC(5,2) NOT NULL,
PRIMARY KEY (student_id, company_id)
);
-- Changing a city is now one row, one place
UPDATE companies SET city = 'Chennai' WHERE name = 'Zoho';
Each fact lives in exactly one table, so updates, inserts and deletes cannot create contradictions.
Data Redundancy, Update Anomaly, Insert Anomaly, Delete Anomaly, Normalization