TechnicalMedium SQL & Databases
What is database normalisation? Explain 1NF, 2NF and 3NF.
Asked for Backend Developer
Why they ask this: A favourite academic and interview topic in Nepal; it also shows you can design clean schemas.
Answer
Normalisation organises tables to remove duplicate data and the update problems it causes.
- 1NF: every column holds a single (atomic) value and there are no repeating groups. Not
skills = "PHP, SQL"; use a separate row per skill. - 2NF: 1NF, and every non-key column depends on the whole primary key. This matters for composite keys: in
(student_id, course_id) → student_name, the name depends only onstudent_id, so move it to astudentstable. - 3NF: 2NF, and non-key columns depend only on the key, not on other non-key columns (no transitive dependency). If
employeesstoresdepartment_idanddepartment_name, move the name to adepartmentstable.
Sometimes you denormalise on purpose for read performance, for example by storing a jobs_count on companies. Do it knowingly and keep the copy in sync.
Can you explain this in your own words?