Database Normal Forms
The normal forms from first through Boyce-Codd, each shown as a table that breaks it and the decomposition that repairs it.
Consider a table recording which students take which courses:
student_id | student_name | course_id | course_title | instructor_name | department
-----------|--------------|-----------|--------------|-----------------|------------
101 | Alice Brown | CS101 | Programming | Dr. Smith | Computing
101 | Alice Brown | CS102 | Algorithms | Dr. Jones | Computing
102 | Bob Wilson | CS101 | Programming | Dr. Smith | Computing
Every enrolment repeats the student’s name, the course title and the instructor. The repetition is not merely wasteful; it is an opening for inconsistency. Updating Dr. Smith’s name means changing every row in which it appears, and deleting the last enrolment for a course deletes everything the table knew about that course. Normalisation is the systematic answer to this: a sequence of normal forms, each ruling out a particular kind of dependency, together with a method of decomposing a relation that violates one into smaller relations that satisfy it, minimising redundancy while preserving the information the original held.
The theory is Codd’s. His 1970 paper introduced the relational model and, with it, the idea of decomposing relations into normal forms to remove such anomalies;1 the 1972 follow-up formally defined the first three normal forms, which remain central to design practice.2 Codd received the 1981 Turing Award for this work, and it is still the theoretical foundation of relational database design.
First normal form
First normal form requires every attribute to hold a single atomic value, with no repeating groups or arrays packed into a cell. It establishes the basic structure of a relational table. The following violates it, since courses holds several values per row:
student_id | name | courses
-----------|-------------|----------------
101 | Alice Brown | CS101, CS102, CS103
102 | Bob Wilson | CS101, MA201
Eliminating the multi-valued courses attribute, with one row for each combination of student and course, gives a table in 1NF, in which each cell holds exactly one value:
student_id | name | course_id
-----------|-------------|----------
101 | Alice Brown | CS101
101 | Alice Brown | CS102
101 | Alice Brown | CS103
102 | Bob Wilson | CS101
102 | Bob Wilson | MA201
Second normal form
Second normal form requires 1NF and, in addition, that there be no partial dependencies, in which a non-key attribute depends on only part of a composite primary key. The table below is in 1NF, its key being the pair of student_id and course_id:
student_id | course_id | student_name | course_title | grade
-----------|-----------|--------------|--------------|-------
101 | CS101 | Alice Brown | Programming | A
101 | CS102 | Alice Brown | Algorithms | B
102 | CS101 | Bob Wilson | Programming | B
Yet student_name depends on student_id alone, and course_title on course_id alone. These partial dependencies are what 2NF forbids. The remedy is to give students and courses tables of their own, leaving in the enrolments table only what depends on the whole key, namely the grade.
Students:
student_id | student_name
-----------|-------------
101 | Alice Brown
102 | Bob Wilson
Courses:
course_id | course_title
----------|-------------
CS101 | Programming
CS102 | Algorithms
Enrolments:
student_id | course_id | grade
-----------|-----------|-------
101 | CS101 | A
101 | CS102 | B
102 | CS101 | B
Third normal form
Third normal form requires 2NF and the absence of transitive dependencies, in which a non-key attribute depends on another non-key attribute rather than directly on the primary key. The following table is in 2NF but not 3NF:
course_id | course_title | instructor_id | instructor_name | department
----------|--------------|---------------|-----------------|------------
CS101 | Programming | 201 | Dr. Smith | Computing
CS102 | Algorithms | 202 | Dr. Jones | Computing
CS103 | Databases | 201 | Dr. Smith | Computing
The chain course_id → instructor_id → instructor_name is the transitive dependency: the course determines the instructor’s name only by way of the instructor, so instructor_name depends on instructor_id rather than directly on the key course_id. Moving instructors into their own table breaks the chain.
Instructors:
instructor_id | instructor_name | department
--------------|-----------------|------------
201 | Dr. Smith | Computing
202 | Dr. Jones | Computing
Courses:
course_id | course_title | instructor_id
----------|--------------|---------------
CS101 | Programming | 201
CS102 | Algorithms | 202
CS103 | Databases | 201
Boyce-Codd normal form
Boyce-Codd normal form, introduced by Raymond Boyce and Codd, strengthens 3NF by requiring that every determinant be a candidate key. It addresses certain edge cases in which a table in 3NF still permits anomalies. Take the business rules that each supervisor works on exactly one project, that a project may have several supervisors, and that a student working on a project has exactly one supervisor for it. The following table is in 3NF but not BCNF:
student_id | project_id | supervisor_id
-----------|------------|---------------
101 | P1 | S1
101 | P2 | S3
102 | P1 | S2
103 | P1 | S1
The dependencies are (student_id, project_id) → supervisor_id and supervisor_id → project_id, so both (student_id, project_id) and (student_id, supervisor_id) are candidate keys. Every attribute belongs to some candidate key, and 3NF, which constrains only non-key attributes, is satisfied. BCNF is not: supervisor_id is a determinant without being a candidate key, and the fact that S1 works on P1 is accordingly recorded once for every student S1 supervises. Decomposing along that dependency gives two tables.3
Supervisors and projects:
supervisor_id | project_id
--------------|------------
S1 | P1
S2 | P1
S3 | P2
Students and supervisors:
student_id | supervisor_id
-----------|---------------
101 | S1
101 | S3
102 | S2
103 | S1
In practice
Normalisation theory gives rigorous rules, but applying them means weighing trade-offs. C.J. Date calls database design ‘an extremely complex task’, in which ‘normalisation theory is a useful aid in the process, but it is not a panacea’.4 The higher normal forms (4NF and 5NF) deal with more complex patterns of dependency, which turn up less often in practice;5 most commercial designs aim for 3NF or BCNF as the best balance between eliminating redundancy and keeping queries simple. Performance can, in particular contexts, justify controlled denormalisation. Data warehouses, for instance, often use deliberately denormalised star schemas to speed up analytical queries.6
Footnotes
-
E.F. Codd, ‘A Relational Model of Data for Large Shared Data Banks’, Communications of the ACM (1970). ↩
-
E.F. Codd, ‘Further Normalization of the Data Base Relational Model’ (1972). ↩
-
The decomposition is lossless but does not preserve dependencies:
(student_id, project_id) → supervisor_idcan no longer be checked within a single table. A BCNF decomposition cannot always preserve dependencies, whereas a 3NF decomposition always can, which is why 3NF remains a respectable stopping point. ↩ -
C.J. Date, An Introduction to Database Systems. ↩
-
Kent’s ‘A simple guide to five normal forms in relational database theory’, in Communications of the ACM, carries the account through to the fourth and fifth. ↩
-
For the fuller textbook treatment of all of the above, see Elmasri and Navathe, Fundamentals of Database Systems. ↩