Database normalization: 1NF, 2NF, 3NF and BCNF with SQL

Database normalization splits tables so each fact is stored once. A school database taken through 1NF, 2NF, 3NF and BCNF, with the SQL and diagram of each.

What is database normalization?

Database normalization is the process of organizing the tables and columns of a relational database to reduce data redundancy and improve data integrity. In practice you split tables until each fact is stored in one place, so it can’t be stored twice with two different values. Courses on normalization in DBMS teach it as a ladder of normal forms: first (1NF), second (2NF), third (3NF) and Boyce-Codd (BCNF). Each is a rule a table meets or breaks, and each includes the one before it.

The rules are written in functional dependencies. A functional dependency X -> Y says that a value of X determines the value of Y: any two rows that agree on X also agree on Y. X is the determinant. A course code determines the course’s title, and a student id determines the student’s name. Normalizing a table means asking which determinant each column hangs on, and moving the column to a table where that determinant is the key.

A table that breaks a normal form stores one fact in many rows, and it shows in three anomalies:

  • Update anomaly: a fact changed in one row and not in another, so the table holds two answers.
  • Insert anomaly: a fact that can’t be stored until an unrelated fact exists.
  • Delete anomaly: a fact lost when the last row that carried it is deleted.

The example is a school, a smaller cut of the student management system template: students, courses, teachers and the enrollments between them. It starts the way a spreadsheet would keep it, one row per student.

First normal form (1NF): one value per column

A table is in first normal form when every column holds a single, atomic value per row, there are no repeating groups, and a primary key tells the rows apart. The school’s first table breaks it, because Courses holds a list:

CREATE TABLE dbo.Student (
  StudentId int           NOT NULL
    CONSTRAINT PK_Student PRIMARY KEY,
  FullName  nvarchar(100) NOT NULL,
  Courses   nvarchar(200) NOT NULL
);
dbo.Student with primary key StudentId and the columns FullName and Courses; no relationships.
Every course a student takes sits in one text column, so there is no line to a course: nothing to point at.
INSERT INTO dbo.Student (StudentId, FullName, Courses)
VALUES (1, N'Maya Chen', N'Algebra, Biology'),
       (2, N'Leo Park', N'Marine Biology, Algebar');
SELECT FullName
FROM dbo.Student
WHERE Courses LIKE N'%Biology%';

SQL Server stores both rows, and the query returns both students. Maya takes Biology; Leo takes Marine Biology, which matches '%Biology%' as well. “Algebar” went in too, since a string can’t have a foreign key. Counting a course’s students or renaming a course turns into string surgery. Splitting the list into Course1, Course2 and Course3 only moves the problem: three columns to search, and nowhere for a fourth course.

The fix gives each course of each student a row of its own. This script replaces dbo.Student, now without Courses, and adds dbo.Enrollment, which copies what the spreadsheet knew about a course into every row:

CREATE TABLE dbo.Student (
  StudentId int           NOT NULL
    CONSTRAINT PK_Student PRIMARY KEY,
  FullName  nvarchar(100) NOT NULL
);
CREATE TABLE dbo.Enrollment (
  StudentId   int           NOT NULL,
  CourseCode  char(3)       NOT NULL,
  CourseTitle nvarchar(100) NOT NULL,
  TeacherId   int           NOT NULL,
  TeacherName nvarchar(100) NOT NULL,
  EnrolledOn  date          NOT NULL,
  CONSTRAINT PK_Enrollment PRIMARY KEY (StudentId, CourseCode),
  CONSTRAINT FK_Enrollment_Student_StudentId
    FOREIGN KEY (StudentId)
    REFERENCES dbo.Student (StudentId)
);
dbo.Student with primary key StudentId; dbo.Enrollment with primary key StudentId and CourseCode and the columns CourseTitle, TeacherId, TeacherName and EnrolledOn; a solid line from Student to Enrollment.
One row per student and course. The course's title and teacher ride along in every row, and no table of their own appears.

Every column holds one value now, and the composite key (StudentId, CourseCode) stops a student from taking the same course twice, which puts the table in 1NF.

Second normal form (2NF): depend on the whole key

A table is in second normal form when it is in 1NF and no non-key column depends on only part of a candidate key. That is a partial dependency, and it needs a key of two or more columns: a table whose candidate keys are all single columns is in 2NF as soon as it is in 1NF.

dbo.Enrollment has three. CourseTitle, TeacherId and TeacherName depend on CourseCode alone; only EnrolledOn needs the whole pair. The anomalies follow:

INSERT INTO dbo.Student (StudentId, FullName)
VALUES (1, N'Maya Chen'), (2, N'Leo Park');
INSERT INTO dbo.Enrollment
  (StudentId, CourseCode, CourseTitle, TeacherId, TeacherName,
   EnrolledOn)
VALUES (1, 'ALG', N'Algebra', 5, N'Ana Ruiz', '2026-09-01'),
       (2, 'ALG', N'Algebra I', 5, N'Ana Ruiz', '2026-09-02');
INSERT INTO dbo.Enrollment
  (StudentId, CourseCode, CourseTitle, TeacherId, TeacherName,
   EnrolledOn)
VALUES (NULL, 'CHE', N'Chemistry', 6, N'Sam Lee', '2026-09-01');
Msg 515, Level 16, State 2, Line 8
Cannot insert the value NULL into column 'StudentId', table 'School.dbo.Enrollment'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Both Algebra enrollments go in, one titled Algebra and one Algebra I, so course ALG now has two titles. Chemistry, which nobody takes yet, can’t be stored at all: StudentId is part of the primary key, and primary key columns can’t be NULL, so Msg 515 refuses the row. That is the insert anomaly. If Maya and Leo both drop Algebra, its title and teacher leave with their rows: the delete anomaly.

The fix moves every column that depends on CourseCode alone into dbo.Course, where the code is unique on its own (AK_Course_CourseCode) and CourseId is the primary key. This replaces dbo.Enrollment, which now holds the CourseId:

CREATE TABLE dbo.Course (
  CourseId    int           NOT NULL
    CONSTRAINT PK_Course PRIMARY KEY,
  CourseCode  char(3)       NOT NULL
    CONSTRAINT AK_Course_CourseCode UNIQUE,
  Title       nvarchar(100) NOT NULL,
  TeacherId   int           NOT NULL,
  TeacherName nvarchar(100) NOT NULL
);
CREATE TABLE dbo.Enrollment (
  StudentId  int  NOT NULL,
  CourseId   int  NOT NULL,
  EnrolledOn date NOT NULL,
  CONSTRAINT PK_Enrollment PRIMARY KEY (StudentId, CourseId),
  CONSTRAINT FK_Enrollment_Student_StudentId
    FOREIGN KEY (StudentId)
    REFERENCES dbo.Student (StudentId),
  CONSTRAINT FK_Enrollment_Course_CourseId
    FOREIGN KEY (CourseId)
    REFERENCES dbo.Course (CourseId)
);
dbo.Course with primary key CourseId, alternate key CourseCode and the columns Title, TeacherId and TeacherName; dbo.Student; dbo.Enrollment with primary key StudentId and CourseId, both foreign keys, and EnrolledOn; solid lines from Course and from Student to Enrollment.
Course facts live in dbo.Course. dbo.Enrollment keeps what needs both a student and a course, and its foreign keys are its primary key, so both lines are solid.
INSERT INTO dbo.Student (StudentId, FullName)
VALUES (1, N'Maya Chen'), (2, N'Leo Park');
INSERT INTO dbo.Course
  (CourseId, CourseCode, Title, TeacherId, TeacherName)
VALUES (1, 'ALG', N'Algebra', 5, N'Ana Ruiz'),
       (2, 'BIO', N'Biology', 5, N'Ana Ruiz-Diaz'),
       (3, 'CHE', N'Chemistry', 6, N'Sam Lee');
INSERT INTO dbo.Enrollment (StudentId, CourseId, EnrolledOn)
VALUES (1, 1, '2026-09-01'), (2, 1, '2026-09-02');
INSERT INTO dbo.Enrollment (StudentId, CourseId, EnrolledOn)
VALUES (2, 9, '2026-09-02');
Msg 547, Level 16, State 1, Line 10
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Enrollment_Course_CourseId". The conflict occurred in database "School", table "dbo.Course", column 'CourseId'.
The statement has been terminated.

Chemistry goes in as a course with no students. Each title is stored once, so ALG can’t have two. And an enrollment in course 9, which doesn’t exist, fails with Msg 547. While courses were a list of names, nothing could check that.

Third normal form (3NF): nothing but the key

A table is in third normal form when it is in second normal form and no non-key column depends on the primary key transitively. A transitive dependency is a non-key column that depends on the key only through another non-key column. With 2NF, that gives the old rule: every non-key column depends on the key, the whole key, and nothing but the key.

dbo.Course is in 2NF, since both its candidate keys are single columns, but TeacherName hangs on TeacherId, not on the course: CourseId -> TeacherId -> TeacherName. The run above shows the cost. Teacher 5 is Ana Ruiz on Algebra and Ana Ruiz-Diaz on Biology, and SQL Server accepted both. Renaming her means updating every course she teaches.

The fix gives teachers a table and leaves only the teacher’s key in dbo.Course. This replaces dbo.Course:

CREATE TABLE dbo.Teacher (
  TeacherId int           NOT NULL
    CONSTRAINT PK_Teacher PRIMARY KEY,
  FullName  nvarchar(100) NOT NULL
);
CREATE TABLE dbo.Course (
  CourseId   int           NOT NULL
    CONSTRAINT PK_Course PRIMARY KEY,
  CourseCode char(3)       NOT NULL
    CONSTRAINT AK_Course_CourseCode UNIQUE,
  Title      nvarchar(100) NOT NULL,
  TeacherId  int           NOT NULL,
  CONSTRAINT FK_Course_Teacher_TeacherId
    FOREIGN KEY (TeacherId)
    REFERENCES dbo.Teacher (TeacherId)
);
dbo.Teacher with primary key TeacherId and FullName; dbo.Course with primary key CourseId, alternate key CourseCode, Title and the foreign key TeacherId, a dashed line from Teacher; dbo.Student; dbo.Enrollment with primary key StudentId and CourseId, solid lines from Course and from Student.
The teacher's name is stored once, in dbo.Teacher. The line to dbo.Course is dashed because TeacherId isn't part of Course's key.

A teacher has one name now, a teacher with no course yet can be stored, and a course can’t name a teacher who doesn’t exist.

Boyce-Codd normal form (BCNF): every determinant is a key

A table is in BCNF when, for every functional dependency X -> Y that holds, with Y not part of X, X is a super key: a candidate key or a set of columns that contains one. In short: every determinant is a candidate key. 3NF lets one case through, a dependency whose right side is part of a candidate key, and that case needs two candidate keys that overlap.

The school adds tutoring. A student has at most one tutor per course, and each tutor coaches a single course. A first design keys tutoring by student and course:

CREATE TABLE dbo.Tutoring (
  StudentId int NOT NULL,
  CourseId  int NOT NULL,
  TeacherId int NOT NULL,
  CONSTRAINT PK_Tutoring PRIMARY KEY (StudentId, CourseId),
  CONSTRAINT FK_Tutoring_Student_StudentId
    FOREIGN KEY (StudentId)
    REFERENCES dbo.Student (StudentId),
  CONSTRAINT FK_Tutoring_Course_CourseId
    FOREIGN KEY (CourseId)
    REFERENCES dbo.Course (CourseId),
  CONSTRAINT FK_Tutoring_Teacher_TeacherId
    FOREIGN KEY (TeacherId)
    REFERENCES dbo.Teacher (TeacherId)
);
dbo.Teacher, dbo.Course, dbo.Student and dbo.Tutoring with primary key StudentId and CourseId and the foreign key TeacherId; solid lines from Student and from Course to Tutoring, dashed lines from Teacher to Tutoring and from Teacher to Course.
dbo.Tutoring is keyed by student and course. That a tutor coaches one course is in no key, so nothing on the diagram shows it.

The dependencies are (StudentId, CourseId) -> TeacherId and TeacherId -> CourseId, which makes (StudentId, TeacherId) a second candidate key, overlapping the first in StudentId. Every column is part of some candidate key, so there is no non-key column to break 3NF. BCNF fails, because TeacherId determines CourseId without being a key:

INSERT INTO dbo.Student (StudentId, FullName)
VALUES (1, N'Maya Chen'), (2, N'Leo Park');
INSERT INTO dbo.Teacher (TeacherId, FullName)
VALUES (5, N'Ana Ruiz'), (7, N'Omar Haddad');
INSERT INTO dbo.Course (CourseId, CourseCode, Title, TeacherId)
VALUES (1, 'ALG', N'Algebra', 5), (2, 'BIO', N'Biology', 5);
INSERT INTO dbo.Tutoring (StudentId, CourseId, TeacherId)
VALUES (1, 1, 7), (2, 2, 7);

Every row goes in. Omar Haddad, teacher 7, now coaches Algebra for Maya and Biology for Leo, against the rule. The fact “teacher 7 coaches Algebra” is copied into each of his rows, and no constraint compares the copies. If Maya leaves, nothing records which course Omar coaches.

The BCNF fix puts that dependency in a table where its determinant is the key, dbo.Tutor, and stores tutoring as a student and a tutor. This replaces dbo.Tutoring:

CREATE TABLE dbo.Tutor (
  TeacherId int NOT NULL
    CONSTRAINT PK_Tutor PRIMARY KEY,
  CourseId  int NOT NULL,
  CONSTRAINT FK_Tutor_Teacher_TeacherId
    FOREIGN KEY (TeacherId)
    REFERENCES dbo.Teacher (TeacherId),
  CONSTRAINT FK_Tutor_Course_CourseId
    FOREIGN KEY (CourseId)
    REFERENCES dbo.Course (CourseId)
);
CREATE TABLE dbo.Tutoring (
  StudentId int NOT NULL,
  TeacherId int NOT NULL,
  CONSTRAINT PK_Tutoring PRIMARY KEY (StudentId, TeacherId),
  CONSTRAINT FK_Tutoring_Student_StudentId
    FOREIGN KEY (StudentId)
    REFERENCES dbo.Student (StudentId),
  CONSTRAINT FK_Tutoring_Tutor_TeacherId
    FOREIGN KEY (TeacherId)
    REFERENCES dbo.Tutor (TeacherId)
);
dbo.Teacher; dbo.Tutor with primary key TeacherId, also a foreign key, and the foreign key CourseId; dbo.Tutoring with primary key StudentId and TeacherId, both foreign keys; solid lines from Teacher to Tutor, from Tutor to Tutoring and from Student to Tutoring; dashed lines from Course to Tutor and from Teacher to Course.
dbo.Tutor is keyed by TeacherId alone, so a tutor has one course; its solid line from dbo.Teacher ends in a ring and a bar at dbo.Tutor.
INSERT INTO dbo.Tutor (TeacherId, CourseId)
VALUES (7, 1);
INSERT INTO dbo.Tutoring (StudentId, TeacherId)
VALUES (1, 7), (2, 7);
INSERT INTO dbo.Tutor (TeacherId, CourseId)
VALUES (7, 2);
Msg 2627, Level 14, State 1, Line 5
Violation of PRIMARY KEY constraint 'PK_Tutor'. Cannot insert duplicate key in object 'dbo.Tutor'. The duplicate key value is (7).
The statement has been terminated.

Omar coaches Algebra, both students book him, and giving him Biology as well fails with Msg 2627 on PK_Tutor.

The split loses one rule. “One tutor per student per course” was the old primary key, and now it spans two tables: on this design, Maya can book a second Algebra tutor and SQL Server takes it. If that rule matters more, keep CourseId in the key of dbo.Tutoring and point a composite foreign key (TeacherId, CourseId) at a unique pair on dbo.Tutor: not BCNF, but both rules hold.

How far should you normalize?

Normalize to 3NF by default, and test for BCNF wherever a table has more than one candidate key, the only place the two differ. Fourth normal form deals with multivalued dependencies: one table recording two independent lists about the same key, say a teacher’s courses and the same teacher’s languages. Fifth deals with join dependencies, where a table splits without loss into three smaller ones but not into two. Both come up less often, and the fix has the same shape: split the table.

Denormalization goes the other way: it stores a value twice on purpose so reads skip a join. It starts from a normalized design, so you know which copy is the source and which ones have to follow it.

How ERDsmith helps

Two titles for ALG, a second name for Ana Ruiz, a tutor on two courses: each came from a column in the wrong table, and each fix was a new table and a relationship. That is design work, cheapest before there are rows to move. In ERDsmith a split is drawn, and the columns and lines follow from the keys:

  • dbo.Tutor gets rounded corners from its one identifying relationship: TeacherId is its whole primary key, so the line from dbo.Teacher is solid . CourseId sits outside the key, so the line from dbo.Course stays dashed .
  • Deleting a table deletes the relationships that point to it, and a migrated column goes with its last relationship, so undoing a split leaves no stray columns behind.