Computer Science · A3.2 · SL and HL

Database normalisation to 3NF

Normalisation questions give you one badly designed table and ask you to fix it. The marks are for naming the exact dependency that breaks each normal form and for tables that still link up afterwards, with their primary and foreign keys shown. Generic definitions copied from notes usually earn half the marks at most.

Written from the stage “Normalisation to 3NF” of the 7Quest Computer Science course. The questions are our own, in the style of the exam; none are from past papers.

Why redundancy is a problem

Imagine an enrolment table with StudentID, StudentName, GroupCode, TutorName, CourseCode, CourseTitle and Grade. The tutor’s name and the course title are repeated in many rows, and that repetition causes three kinds of anomaly.

An insertion anomaly means you cannot add one fact without inventing others: a new course cannot be recorded until someone enrols on it. An update anomaly means the same data sits in several rows, so changing only some copies makes the database inconsistent: change Mr Mills’s name in one row and group 12A has two tutors. A deletion anomaly means deleting one record loses something else: if the only student taking Physics leaves, the fact that the Physics course exists disappears with her.

Normalisation is the process of organising data into tables that follow the normal forms (1NF, 2NF, 3NF) to reduce redundancy and remove these anomalies.

Functional dependencies

The normal forms are defined with functional dependencies. A→BA \rightarrow B means that once you know A, B is determined. StudentID→StudentName\text{StudentID} \rightarrow \text{StudentName} because each student has exactly one name.

Two kinds of dependency break the normal forms. A partial dependency is a non-key attribute that depends on only part of a composite primary key: with the key (StudentID, CourseCode), StudentID→StudentName\text{StudentID} \rightarrow \text{StudentName} is partial. A transitive dependency is a non-key attribute that depends on another non-key attribute, and so only indirectly on the key: StudentID→GroupCode→TutorName\text{StudentID} \rightarrow \text{GroupCode} \rightarrow \text{TutorName}.

1NF, 2NF and 3NF

A table is in 1NF when every cell holds a single atomic value, there are no repeating groups (no lists in a cell, no Course1, Course2, Course3 columns) and every row is unique, with a primary key.

It is in 2NF when it is in 1NF and no non-key attribute depends on only part of the primary key. If the key is a single field (and there is no composite candidate key), a table in 1NF is already in 2NF, because there is no part of the key to depend on.

It is in 3NF when it is in 2NF and no non-key attribute depends on another non-key attribute. The usual summary is that every non-key attribute depends on the key (1NF), the whole key (2NF) and nothing but the key (3NF).

Normalising step by step

For the enrolment table: to reach 1NF, give each student-and-course pair its own row and choose the key (StudentID, CourseCode). Then write down every dependency: StudentID→StudentName,GroupCode\text{StudentID} \rightarrow \text{StudentName}, \text{GroupCode}; GroupCode→TutorName\text{GroupCode} \rightarrow \text{TutorName}; CourseCode→CourseTitle\text{CourseCode} \rightarrow \text{CourseTitle}; and (StudentID,CourseCode)→Grade(\text{StudentID}, \text{CourseCode}) \rightarrow \text{Grade}.

To reach 2NF, move the partial dependencies out: Student(StudentID, StudentName, GroupCode) and Course(CourseCode, CourseTitle). Only Grade stays in Enrolment, because it needs the whole key. To reach 3NF, remove the transitive dependency from Student by creating TutorGroup(GroupCode, TutorName) and keeping GroupCode in Student as a foreign key.

The column that links two tables stays in both, as the primary key in one and a foreign key in the other. Drop GroupCode from Student and you lose which group each student is in.

When to denormalise

Denormalisation means putting controlled redundancy back on purpose, for example storing CustomerName in an orders table or keeping a calculated TotalAmount column, so that some queries need fewer joins and run faster. The cost is the return of everything normalisation removed: more storage, update anomalies, a risk of inconsistent copies and slower writes. It is worth it in a read-heavy system that is loaded periodically, such as a reporting database, and rarely worth it in a transactional system with many updates. An “evaluate” answer needs a benefit with its mechanism, a drawback with its mechanism and a conclusion that depends on the context.

Where the marks go

  • Explaining an anomaly with a definition and no example. Use the table in the question: name the value that is repeated and what goes wrong.
  • Calling every dependency “partial”. Partial needs a composite key; a dependency between two non-key attributes is transitive.
  • Splitting tables and dropping the linking column, so the original data can no longer be rebuilt.
  • Leaving out the primary and foreign keys in the final tables. Underline or label them.
  • Saying a table with a single-field key can still have a partial dependency.

Three questions to try

Answer on paper first, then open the markscheme and mark yourself honestly. A mark only counts if your answer says that point.

Identify4 marksPaper 1 style

A sports centre stores class bookings in one table. The primary key is (MemberID, ClassCode). Each class always runs in the same room, and each room has a fixed capacity.
(a) Identify one partial dependency and one transitive dependency in this table. [2]
(b) Explain an update anomaly that could occur in this table. [2]

Booking
MemberIDClassCodeMemberNameClassNameRoomNoRoomCapacity
M01Y1Lena OrtizYogaR220
M01SPLena OrtizSpinR115
M02Y1Tom HaleYogaR220
M03SPPriya NairSpinR115
M03PLPriya NairPilatesR220
Show the markscheme

Markscheme (4 marks)

  1. (a) Partial: MemberID → MemberName (or ClassCode → ClassName / RoomNo), which depends on only part of the key [1]
  2. (a) Transitive: RoomNo → RoomCapacity, a non-key attribute depending on another non-key attribute (ClassCode → RoomNo → RoomCapacity) [1]
  3. (b) The same data is stored in several rows, e.g. RoomCapacity 20 for R2 appears in three rows [1]
  4. (b) If R2’s capacity changes and only some rows are updated, R2 has two different capacities and the data is inconsistent [1]

A full-marks answer

(a) MemberName depends only on MemberID, which is part of the composite key (MemberID, ClassCode), so MemberID → MemberName is a partial dependency. RoomCapacity depends on RoomNo, which is not part of the key, so ClassCode → RoomNo → RoomCapacity is a transitive dependency.
(b) The capacity of room R2 (20) is stored in three separate rows. If the room is refitted to hold 25 and only the Yoga rows are updated, the Pilates row still says 20, so the table gives two different capacities for the same room.

Construct5 marksPaper 1 style

Normalise the Booking table from the previous question to third normal form. Show each table with its attributes, and identify the primary key and any foreign keys.

Show the markscheme

Markscheme (5 marks)

  1. Member(MemberID, MemberName) with MemberID as primary key [1]
  2. Class(ClassCode, ClassName, RoomNo) with ClassCode as primary key [1]
  3. Room(RoomNo, RoomCapacity) with RoomNo as primary key, and RoomNo in Class as a foreign key [1]
  4. Booking(MemberID, ClassCode) with the composite primary key [1]
  5. MemberID and ClassCode in Booking are foreign keys to Member and Class [1]

A full-marks answer

Removing the partial dependencies gives a Member table and a Class table, and removing the transitive dependency RoomNo → RoomCapacity from Class gives a Room table:
Member(MemberID, MemberName)
Class(ClassCode, ClassName, RoomNo), where RoomNo is a foreign key to Room
Room(RoomNo, RoomCapacity)
Booking(MemberID, ClassCode), where the composite primary key is made of two foreign keys, to Member and to Class
Every non-key attribute now depends on the whole key of its table and on nothing else, and the original table can be rebuilt by joining Booking, Member, Class and Room.

Explain3 marksPaper 1 style

Before the Booking table was designed, the centre kept one row per member, with a column Classes that held values such as “Yoga, Spin”. Explain why that table was not in first normal form and how it would be converted to 1NF.

Show the markscheme

Markscheme (3 marks)

  1. The Classes column holds more than one value in a cell: the values are not atomic (a repeating group) [1]
  2. To convert, create a separate row for each member and class combination, with a single class in each cell [1]
  3. Choose a primary key that makes each row unique, such as (MemberID, ClassCode) [1]

A full-marks answer

First normal form needs every cell to hold a single atomic value. A Classes cell containing “Yoga, Spin” holds a list, which is a repeating group, so the table is not in 1NF; it also makes it awkward to find, for example, everyone booked on Spin. To convert it, give each member and class combination its own row, so Lena Ortiz appears once for Yoga and once for Spin, and use the composite primary key (MemberID, ClassCode) so that every row is unique.

Where this is in 7Quest

It is in Deep Archive, the part of the Computer Science map for Databases:

  • Normalisation to 3NFSyllabus A3.2.5, A3.2.6, A3.2.7 · 3 exam-style questions

Each stage has a short lesson, quick questions, a minigame and exam-style questions marked point by point, and what you get wrong comes back in your review a few days later. If this is the topic you find hardest, you can choose Databases as your free Computer Science topic and do all of it without paying or giving a card. Full access is a subscription per subject that renews each September and stops after your final exams, so nothing is charged once you have finished (prices and details).

Questions students ask about this

Do I need to know BCNF or 4NF?

No. The guide stops at third normal form, plus evaluating when denormalisation is worth it.

Is normalisation in Paper 1 or Paper 2?

Databases are part of theme A, so in the 2027 guide they are assessed in Paper 1. SQL queries on a normalised design come from the same topic.

What is the difference between a partial and a transitive dependency?

A partial dependency is on part of a composite primary key. A transitive dependency is on another non-key attribute. A table with a single-field key cannot have a partial dependency, but it can have a transitive one.