We’re moving to a new home! Our website is currently in test mode while we update and transfer our content. Some pages and resources may be temporarily unavailable. We’ll be back with all resources shortly. Thank you for your patience.

IB Computer Science | A3.2.6 Constructing Databases in 3NF

Lesson objective

Construct databases in 3NF by identifying entities, keys and dependencies, removing repeating groups and partial or transitive dependencies, and preserving relationships.

Learn

A3.2.6 | CONSTRUCTING DATABASES IN 3NF

01 | FROM EXPLAINING TO CONSTRUCTING

In A3.2.5 you explained why tables change during normalization. Now you must build the design yourself. A good answer shows tables, attributes, primary keys and foreign keys and explains why each fact belongs where you put it.

Start with the real-world rules. A library lends physical copies, not just book titles. A hospital records appointments, not just patient names. An online shop must remember the price charged on an order, even if the current product price changes tomorrow.

There is rarely one correct list of tables for every organization. The model is correct only for its stated assumptions. The examples below are teaching models, not complete operational systems.

Revisit keys, dependencies and normal forms if those terms are still unfamiliar.

02 | A REPEATABLE DESIGN METHOD

  1. Read the requirements. Identify the things, events and relationships the system must record.
  2. State the rules. Can a book have several authors? Can a student enrol more than once? Does each department have one office?
  3. Identify candidate keys. Find minimal unique identifiers. Choose primary keys; do not assume names are unique.
  4. Write dependencies. Ask which attributes determine other attributes. Analyze all candidate keys.
  5. Reach 1NF. Remove lists and repeating column groups; give each row a unique identity.
  6. Reach 2NF. Move non-key facts that depend on only part of a composite candidate key.
  7. Reach 3NF. Move non-key facts determined through another non-key attribute.
  8. Reconnect and test. Keep foreign keys, preserve the original information, and try inserting, updating and deleting sample records.

PK means primary key; FK means foreign key. Where two fields are marked “PK part”, together they form one composite primary key.

03 | LIBRARY: UNDERSTAND WHAT A LOAN MEANS

The library has members, book editions and physical copies. A title can have several copies and several authors. A member can borrow a copy again after returning it.

Our rules: MemberID identifies a member. BookID identifies a book edition, with one title. CopyID identifies a physical copy belonging to one BookID. LoanID identifies one borrowing event. One loan has one member, one copy, a loan date and a due date.

Starting list: several loans are packed into one cell
MemberIDMemberNameBorrowed items
M01AlexL01: C10, Robot Design, 2026-10-01, due 2026-10-15; L02: C20, Python Basics, 2026-10-02, due 2026-10-16
M02RinL03: C11, Robot Design, 2026-10-03, due 2026-10-17

This structure is awkward to query. We cannot easily sort individual due dates or update one loan. First make each borrowing event a row.

04 | LIBRARY: 1NF AND THE 2NF CHECK

1NF: one loan per row, one value per cell
LoanID (PK)MemberIDMemberNameCopyIDBookIDTitleLoanDateDueDate
L01M01AlexC10B01Robot Design2026-10-012026-10-15
L02M01AlexC20B02Python Basics2026-10-022026-10-16
L03M02RinC11B01Robot Design2026-10-032026-10-17

The cells are atomic, and LoanID uniquely identifies each row. Under these rules, assume no other candidate key. LoanID is a single-attribute key, so there can be no partial-key dependency. This 1NF table already meets 2NF.

Normalization does not always mean splitting a table at every stage. We still have transitive dependencies:

LoanID → MemberID → MemberName

LoanID → CopyID → BookID → Title

MemberName describes the member, not the loan. Title describes the book edition, not the individual borrowing event. If Alex changes name, we should not need to edit every loan.

05 | LIBRARY: CONSTRUCT THE 3NF TABLES

MEMBER(MemberID PK, MemberName)

BOOK(BookID PK, Title)

COPY(CopyID PK, BookID FK)

LOAN(LoanID PK, MemberID FK, CopyID FK, LoanDate, DueDate)

MEMBER: member facts
MemberID (PK)MemberName
M01Alex
M02Rin
BOOK: book-edition facts
BookID (PK)Title
B01Robot Design
B02Python Basics
COPY: two different copies belong to B01
CopyID (PK)BookID (FK)
C10B01
C11B01
C20B02
LOAN: borrowing events and their dates
LoanID (PK)MemberID (FK)CopyID (FK)LoanDateDueDate
L01M01C102026-10-012026-10-15
L02M01C202026-10-022026-10-16
L03M02C112026-10-032026-10-17

Follow one loan: L03 links to member M02 (Rin) and copy C11. C11 links to B01 (Robot Design). We can recover the original information by joining tables through those keys.

LoanDate and DueDate belong to the borrowing event. In this example, due dates can be adjusted per loan; they are not determined solely by LoanDate. A policy that makes one field determine another may require a different design.

06 | LIBRARY: MANY AUTHORS, MANY BOOKS

Do not add Author1, Author2 and Author3 columns. One book may have several authors, and one author may write several books. Model this many-to-many relationship with a junction table:

AUTHOR(AuthorID PK, AuthorName)

BOOK_AUTHOR(BookID PK part/FK, AuthorID PK part/FK)

AUTHOR
AuthorID (PK)AuthorName
A01Taylor
A02Morgan
BOOK_AUTHOR: B01 has two authors; A01 wrote two books
BookID (PK part/FK)AuthorID (PK part/FK)
B01A01
B01A02
B02A01

The pair prevents the same author–book link being recorded twice. Neither ID is unique on its own in this table. Links are allowed to repeat an ID: that is how the relationship is represented.

07 | SCHOOL: A COMPOSITE-KEY EXAMPLE

A school records enrolments in course offerings. An OfferingID identifies a particular class in a particular period; a CourseID identifies its subject or course definition. Each offering has one teacher. Each student can enrol once per offering, with one grade.

1NF: composite primary key (StudentID, OfferingID)
StudentID (PK part)StudentNameOfferingID (PK part)CourseIDCourseTitleTeacherIDTeacherNameGrade
S01AlexO10CSComputingT01LeeA
S01AlexO20MAMathematicsT02SamB
S02RinO10CSComputingT01LeeB

To reach 2NF: StudentName depends only on StudentID; the offering details depend only on OfferingID. Grade depends on the whole student–offering pair.

STUDENT(StudentID PK, StudentName)

OFFERING(OfferingID PK, CourseID, CourseTitle, TeacherID, TeacherName)

ENROLMENT(StudentID PK part/FK, OfferingID PK part/FK, Grade)

To reach 3NF: CourseID determines CourseTitle and TeacherID determines TeacherName. Move those indirectly dependent facts out of OFFERING:

STUDENT(StudentID PK, StudentName)

COURSE(CourseID PK, CourseTitle)

TEACHER(TeacherID PK, TeacherName)

OFFERING(OfferingID PK, CourseID FK, TeacherID FK)

ENROLMENT(StudentID PK part/FK, OfferingID PK part/FK, Grade)

Keep the two identifiers in ENROLMENT so we can identify whose grade belongs to which class. The school’s rules determine whether team teaching or multiple assessments need extra tables.

08 | HOSPITAL MANAGEMENT

A clinic records appointments. Each appointment has one patient and one doctor. Each doctor belongs to one department; each department has one recorded name.

Dependencies:

PatientID → PatientName

DoctorID → DoctorName, DepartmentID

DepartmentID → DepartmentName

AppointmentID → PatientID, DoctorID, AppointmentDateTime

A 3NF design under these rules:

PATIENT(PatientID PK, PatientName)

DEPARTMENT(DepartmentID PK, DepartmentName)

DOCTOR(DoctorID PK, DoctorName, DepartmentID FK)

APPOINTMENT(AppointmentID PK, PatientID FK, DoctorID FK, AppointmentDateTime)

Do not copy DoctorName or DepartmentName into every appointment. A department name changes once in DEPARTMENT. If doctors can belong to several departments, use DOCTOR_DEPARTMENT instead of one DepartmentID in DOCTOR.

09 | E-COMMERCE

A customer places orders. Each order has lines; the same product may occur on multiple lines, so use (OrderID, LineNumber) to identify a line. Quantity and the agreed unit price belong to that line.

Dependencies:

CustomerID → CustomerName

ProductID → ProductName, CurrentPrice

OrderID → CustomerID, OrderDate

(OrderID, LineNumber) → ProductID, Quantity, UnitPriceAtOrder

A 3NF design under these rules:

CUSTOMER(CustomerID PK, CustomerName)

PRODUCT(ProductID PK, ProductName, CurrentPrice)

SALES_ORDER(OrderID PK, CustomerID FK, OrderDate)

ORDER_LINE(OrderID PK part/FK, LineNumber PK part, ProductID FK, Quantity, UnitPriceAtOrder)

CurrentPrice and UnitPriceAtOrder are different facts. The price charged may depend on the order line, discounts and time. Keeping it on ORDER_LINE preserves history; changing CurrentPrice must not rewrite old orders. A line total can be calculated as Quantity × UnitPriceAtOrder.

10 | EMPLOYEE MANAGEMENT

Each employee belongs to one department. Each department has one name and one office. Store those department facts separately from employee facts.

Dependencies:

EmployeeID → EmployeeName, DepartmentID

DepartmentID → DepartmentName, Office

A 3NF design under these rules:

DEPARTMENT(DepartmentID PK, DepartmentName, Office)

EMPLOYEE(EmployeeID PK, EmployeeName, DepartmentID FK)

EmployeeID → DepartmentID → Office is transitive in a combined employee table. If people work across several departments, replace the single link with EMPLOYEE_DEPARTMENT and put allocation details on that relationship.

11 | INVENTORY MANAGEMENT

A product can be stored in several warehouses. Each product–warehouse pair has one quantity on hand.

Dependencies:

ProductID → ProductName

WarehouseID → WarehouseName

(ProductID, WarehouseID) → QuantityOnHand

A 3NF design under these rules:

PRODUCT(ProductID PK, ProductName)

WAREHOUSE(WarehouseID PK, WarehouseName)

STOCK(ProductID PK part/FK, WarehouseID PK part/FK, QuantityOnHand)

QuantityOnHand cannot depend only on ProductID: the amount can differ by warehouse. Both identifiers are needed. If a warehouse tracks several bins or batches per product, those identifiers must also be considered.

12 | POLICE CRIME REPORTING

Each incident is recorded under one offence category and one reporting officer. Other officers may be assigned to it. These are role-specific links, not a list of names in the incident row.

Dependencies:

OffenceCode → OffenceDescription

OfficerID → OfficerName

IncidentID → OffenceCode, ReportedAt, LocationText, ReportingOfficerID

A 3NF design under these rules:

OFFENCE_TYPE(OffenceCode PK, OffenceDescription)

OFFICER(OfficerID PK, OfficerName)

INCIDENT(IncidentID PK, OffenceCode FK, ReportedAt, LocationText, ReportingOfficerID FK → OFFICER)

INCIDENT_OFFICER(IncidentID PK part/FK, OfficerID PK part/FK)

ReportingOfficerID references OFFICER. Incident assignments use the junction table. If one incident has several offence categories, introduce INCIDENT_OFFENCE. Use fictional records for practice; a real system requires additional access and integrity controls.

13 | CHECK YOUR DESIGN BEFORE YOU FINISH

  • Every row has a valid key; every cell holds one value.
  • Non-key fields depend on the whole of each candidate key.
  • Non-key fields do not depend transitively on keys in these simple examples.
  • Foreign keys refer to the intended parent tables.
  • Many-to-many relationships have suitable junction tables.
  • Repeated events, such as borrowing the same copy again, can be represented.
  • The original facts can be reconstructed without invented combinations or missing links.

Test concrete events: add an unborrowed book, rename a teacher, change a mentor’s email, and remove one enrolment. If those changes force you to alter unrelated rows or lose unrelated facts, revisit the dependencies.

Normalizing a design is different from implementing constraints. Foreign keys, uniqueness rules and business constraints still need to be enforced in the database.

PUT THE FACT IN THE RIGHT TABLE

Use the assumptions of the worked examples.

Terminology

Terminology

Entity

A thing or concept about which data is recorded, such as a member, product or appointment.

Attribute

A field describing an entity or relationship.

Candidate key

A minimal set of fields guaranteed to uniquely identify a row.

Primary key

The candidate key chosen to identify rows.

Foreign key

Field or fields referencing a key in a related table.

Composite key

A key requiring more than one attribute.

Functional dependency

X → Y means each X value determines one Y value under the data rules.

Junction table

A table representing links in a many-to-many relationship.

Partial dependency

A non-prime attribute depends on only a proper subset of a candidate key.

Transitive dependency

An attribute depends on a key through another attribute, such as EmployeeID → DepartmentID → Office.

Lossless decomposition

Splitting tables so their valid joins can reconstruct the original information without extra or missing tuples.

Historical fact

A value tied to an earlier event, such as the unit price actually charged on an order.

Questions

Questions

CHECK THE DESIGN DECISIONS

Select all correct options. Each exact set earns one point.

1. Which should be represented as separate entities in the library?
2. Why use LoanID rather than only (MemberID, CopyID)?
3. Which are partial dependencies in a combined enrolment table keyed by (StudentID, OfferingID)?
4. Which should be removed from PROJECT or OFFERING into its own table?
5. Which price belongs in ORDER_LINE?
6. Which correctly identifies one STOCK row under the example rules?
7. Which statements about normalization are correct?
8. How should several authors be linked to several books?

CONSTRUCTION CHALLENGES

Draw the tables in your book. Mark keys, add sample rows and explain the dependencies. Reveal the sample only after completing your design. These are original practice tasks, not official IB questions or mark schemes.

1. LIBRARY: Construct the four main 3NF tables, then add author support. State every PK and FK.

2. SCHOOL: A row contains StudentID, StudentName, OfferingID, CourseID, CourseTitle, TeacherID, TeacherName and Grade. Construct 3NF tables and explain two dependencies you removed.

3. HOSPITAL: Construct a 3NF model for the stated clinic rules. Explain where DepartmentName belongs.

4. E-COMMERCE: Design orders and their lines so repeat product lines and historical prices are supported.

5. EMPLOYEE: Normalize EmployeeID, EmployeeName, DepartmentID, DepartmentName and Office. State an assumption.

6. INVENTORY: Construct tables for products stocked in several warehouses. Explain the key for quantity.

7. CRIME REPORTING: Design incident categories, reporting officers and multiple officer assignments.

8. TEST YOUR DESIGN: Choose one scenario. Give an insertion, update and deletion test, and explain how the tables avoid unrelated data loss.

Flashcards

Flashcards

Click to flip each card. Select the ideas you need to revisit.

0 cards selected for revision.

    Selections are kept while this page is open.

    Workbook

    Workbook

    COMING SOON

    The A3.2.6 workbook is coming soon. Use the construction challenges to practise table layouts, keys, relationships and dependency explanations in your book.