Relational Model, ER Diagrams, and Normalisation

You can read this note directly if you know what a table is. The main idea is that a relational database stores related facts in tables and uses keys to connect them.

This note answers three beginner questions:

  1. How should we separate facts into suitable tables?
  2. How do keys identify records and connect tables?
  3. How do ER diagrams and normalisation help us design a better database?

The Beginner Problem Relational Design Solves

A spreadsheet can store data, but it does not automatically show which facts belong together.

Example fact types:

FactBetter home
Aisha is a studentStudent table
class 24S01 has tutor Ms LimClass table
Aisha borrowed Data TrailsLoan table

Relational design asks: what are the separate entities, and how are they connected?

A weak design stores many different kinds of facts in one table. A better relational design stores each kind of fact in a suitable table, then uses keys to reconnect the facts when needed.

Table, Record, Field, Attribute

TermBeginner meaning
tablea grid of related data
recordone row in the table
fieldone column in the table
attributea property represented by a field

Example Student table:

student_idnameclass_id
101Aisha24S01
102Bo24S02

student_id, name, and class_id are fields. The first row is one record. The attribute name describes a property of each student.

A table is not automatically a good database design. The fields in a table should describe the same kind of entity or relationship.

Entities and Relationships

An entity is a thing about which data is stored. In a school library example, possible entities include:

EntityPossible attributes
Studentstudent_id, name, class_id
Classclass_id, class_name, tutor
Bookbook_id, title, author
Loanloan_id, student_id, book_id, loan_date

A relationship describes how entities are connected.

Examples:

A Class has Students.
A Student borrows Books.
A Book appears in Loans.

The Loan table is useful because borrowing is not just a property of a student or a book. It is a relationship between a student and a book at a particular time.

Keys

A key helps identify or link records.

Key typeMeaningExample
primary keyuniquely identifies one record in a tablestudent_id in Student
foreign keyreferences a primary key in another tableclass_id in Student
composite keyprimary key made from more than one field(student_id, book_id) in Loan
candidate keyany minimal field or field combination that can uniquely identify a recordstudent_id or a unique school email in Student
secondary keya candidate key not selected as the primary key; it still uniquely identifies a recordunique school email when student_id is the primary key

Caption: Student.class_id is a foreign key because its value should match the primary key Class.class_id.

Why not use name as a primary key? Names may repeat or change. A stable ID such as student_id is usually safer because it is designed to identify exactly one record.

Do not use secondary key here to mean any convenient search field. In this syllabus and its anchor notes, a secondary key is an alternative candidate key, so uniqueness is required. A non-unique field such as class_id may still be searched or indexed, but it is not a candidate or secondary key under this definition.

A composite key must still uniquely identify one record. For example, (student_id, book_id) only works as a loan key if the design assumes the same student cannot have multiple separate loan records for the same book. Otherwise, a separate loan_id or another identifying field would be needed.

Primary Key Versus Foreign Key

A primary key belongs to the table where it uniquely identifies a record.

A foreign key is stored in another table so that a record can refer back to the primary key.

Example:

Class(class_id, class_name, tutor)
Student(student_id, name, class_id)

Here:

  • Class.class_id is the primary key of Class;
  • Student.student_id is the primary key of Student;
  • Student.class_id is a foreign key that refers to Class.class_id.

This means that a student record does not need to repeat the tutor name. It only stores the class ID, and the class ID can be used to find the class details.

What Makes a Good Primary Key?

A good primary key should be:

PropertyMeaning
uniqueno two records have the same key value
stablethe value should not change often
minimalit should not include unnecessary fields
non-nullevery record must have a key value

Weak choices:

Possible keyProblem
namenames may repeat or change
phone_numberphone numbers may change or be shared
class_id in Studentmany students can be in the same class

A designed ID such as student_id is usually safer.

Why Not One Big Table?

Suppose a flat table stores loan data:

loan_idstudent_nameclass_nametutorbook_title
1Aisha24S01Ms LimNetworks
2Ben24S01Ms LimDatabases

The tutor Ms Lim is repeated for every student in class 24S01. This is redundancy.

Problems:

  • if the tutor changes, many rows must be updated;
  • if one row is missed, the database becomes inconsistent;
  • if all students from a class are deleted, the class-tutor information may be lost.

These are not just storage problems. They are reliability problems.

Redundancy and Anomalies

Data redundancy means the same data is stored more than once unnecessarily.

Redundancy can lead to anomalies:

AnomalyMeaningExample
insertion anomalydifficult to add one fact without another unrelated factcannot store a new class unless a student has borrowed a book
update anomalythe same fact must be edited in many placestutor name must be changed in every matching row
deletion anomalydeleting one record accidentally removes the only copy of another factdeleting the last loan from a class removes the only record of its tutor

A good relational design reduces these problems by storing each fact in the right place.

Data Dependency

Data dependency means one data item depends on another.

Example:

class_id -> tutor

Read this as:

Once the class_id is known, the tutor can be determined.

If the tutor depends on the class, then tutor should be stored with class data, not repeated inside every student or loan record.

More examples:

student_id -> student_name, class_id
book_id -> book_title, author
loan_id -> student_id, book_id, loan_date

Dependencies help us decide which fields belong together in the same table.

Normalisation to 3NF

Normalisation is a disciplined way to split data into well-designed tables.

Beginner version:

FormPractical question
1NFAre values atomic, with no repeated groups inside one field?
2NFIf a table has a composite key, does every non-key field depend on the whole key?
3NFDo non-key fields depend only on the key, not on another non-key field?

The target for H2 Computing is usually third normal form, or 3NF.

How to Think During Normalisation

Ask these questions:

  1. What is this table really about?
  2. Which field identifies one record?
  3. Which non-key fields depend on the key?
  4. Does any non-key field depend on another non-key field?
  5. After splitting, what foreign keys are needed to reconnect the data?

Normalisation should preserve meaning. It should not split tables randomly.

From Flat Table to 3NF: A Worked Example

Suppose the first design is one large table:

LoanRecord(loan_id, student_id, student_name, class_id, tutor, book_id, book_title, author, loan_date)

A few rows may look like this:

loan_idstudent_idstudent_nameclass_idtutorbook_idbook_titleauthorloan_date
1101Aisha24S01Ms Lim501NetworksA Wong2026-07-08
2102Ben24S01Ms Lim502DatabasesM Tan2026-07-08
3101Aisha24S01Ms Lim502DatabasesM Tan2026-07-09

This table is understandable, but it repeats facts.

Step 1: Identify Dependencies

Look for fields that determine other fields:

student_id -> student_name, class_id
class_id -> tutor
book_id -> book_title, author
loan_id -> student_id, book_id, loan_date

This means:

DependencyDesign implication
student_id -> student_name, class_idstudent facts belong in Student
class_id -> tutorclass facts belong in Class
book_id -> book_title, authorbook facts belong in Book
loan_id -> student_id, book_id, loan_dateloan facts belong in Loan

Caption: Each functional dependency points to a suitable table: store facts with the key they depend on, then reconnect tables using primary and foreign keys.

Step 2: Split Facts into Suitable Tables

A better design is:

Student(student_id, student_name, class_id)
Class(class_id, tutor)
Book(book_id, book_title, author)
Loan(loan_id, student_id, book_id, loan_date)

Here:

  • student facts go in Student;
  • class facts go in Class;
  • book facts go in Book;
  • loan facts go in Loan.

Step 3: Keep Foreign Keys

The split tables must still be connected:

Foreign keyRefers toPurpose
Student.class_idClass.class_idfind the student’s class and tutor
Loan.student_idStudent.student_idfind who borrowed the book
Loan.book_idBook.book_idfind which book was borrowed

The data is split, but keys make it possible to reconnect it.

Step 4: Trace One Query Idea Through the Design

Question:

Which book did Aisha borrow, and on what date?

Reasoning:

StepTable usedReason
find Aisha’s student IDStudentstudent_name is stored with student facts
find Aisha’s loan recordsLoanLoan.student_id links to Student.student_id
find book titlesBookLoan.book_id links to Book.book_id
show datesLoanloan_date belongs to the borrowing event

This is why normalised data can still be useful. The facts are separated, but SQL joins can reconnect them.

1NF, 2NF, and 3NF in Beginner Language

First Normal Form: 1NF

A table is in 1NF when each field contains atomic values and there are no repeated groups inside a single field.

Weak design:

student_idnameborrowed_books
101AishaNetworks, Databases

Problem: borrowed_books stores multiple values in one field.

Better design:

student_idbook_idloan_date
1015012026-07-08
1015022026-07-09

Each loan is a separate record.

Second Normal Form: 2NF

2NF requires the table first to be in 1NF. It matters especially when a candidate key is composite: every non-key field must depend on the whole candidate key, not just part of it. The field or fields on the left of a dependency arrow are the determinant; the fields determined by them are the dependents.

Example weak design:

Enrollment(student_id, subject_id, student_name, subject_title, enrolment_date)

Assume that a student has at most one current enrolment in a subject, so (student_id, subject_id) is a candidate key:

  • student_name depends only on student_id;
  • subject_title depends only on subject_id;
  • enrolment_date depends on the whole composite key.

The first two are partial dependencies, so student and subject details should be moved to their own tables.

Third Normal Form: 3NF

3NF requires the table first to be in 2NF. Non-key fields must then depend on a candidate key without depending transitively through another non-key field.

Example weak design:

Student(student_id, student_name, class_id, tutor)

Here:

student_id -> class_id
class_id -> tutor

So tutor depends on class_id, which is not the primary key of Student. The tutor should be stored in Class, not repeated in Student.

Better design:

Student(student_id, student_name, class_id)
Class(class_id, tutor)

ER Diagrams

An ER diagram shows entities and relationships.

Caption: Read the relationship in both directions. In this model, one Customer may place zero or many Orders (0..*), while every Order belongs to exactly one Customer (1). A non-null foreign key in Order makes that membership compulsory; allowing it to be NULL would make the Order-to-Customer link optional.

Common relationship types:

Relationship typeMeaningExample
one-to-oneone record in A relates to one record in Bone person has one school account
one-to-manyone record in A relates to many records in Bone class has many students
many-to-manymany records in A relate to many records in Bmany students can borrow many books

Cardinality also has a minimum, called optional or mandatory participation. Recognise these endpoint meanings in crow’s-foot-style ER diagrams:

Endpoint meaningRange notationInterpretation
exactly one1one related record is compulsory
zero or one0..1the relationship is optional, with at most one match
one or more1..*at least one match is compulsory
zero or more0..*any number of matches, including none

The symbol nearest an entity describes how many instances of that entity may participate for one instance at the opposite end. Always read a relationship in both directions.

In textual schema diagrams, this wiki labels keys as PK and FK. Anchor ER/schema diagrams may instead use a solid underline for a primary key and a dashed underline for a foreign key; students should recognise both conventions and label their own diagrams consistently.

Example relationships:

One Class has many Students.
One Student can have many Loans.
One Book can appear in many Loans over time.

A many-to-many relationship is usually resolved using a linking table. For example, Student and Book are connected through Loan.

Caption: Loan resolves the many-to-many relationship by storing one borrowing event per row, with foreign keys to both Student and Book.

From ER Diagram to Tables

A simple way to move from ER thinking to table design is:

  1. Turn each main entity into a table.
  2. Choose a primary key for each table.
  3. Add foreign keys to represent relationships.
  4. Use a linking table for many-to-many relationships.
  5. Check whether repeated facts can cause anomalies.

Example:

ER ideaTable design
Class has many StudentsStudent stores class_id as a foreign key
Student borrows BookLoan links student_id and book_id
Book has title and authorBook stores book_title and author once

Wrong Versus Better

Weak statementBetter statement
A database is just many tables.A relational database stores related facts in tables and connects them using keys.
A primary key is any important field.A primary key uniquely identifies one record in a table.
A foreign key is a key in another table.A foreign key is a field in one table that references the primary key of another table.
Normalisation means splitting tables.Normalisation means reducing redundancy and dependency problems while preserving relationships.
3NF means there is no repeated data at all.3NF reduces unnecessary repetition by ensuring non-key fields depend on the key, not on other non-key fields.

How to Answer This in Exams

For a key question:

State the key type, identify the field, and explain its role.

Example:

student_id is the primary key of Student because it uniquely identifies each student record.

For a foreign key question:

State the field, the table it is in, the table it references, and why it is needed.

Example:

Student.class_id is a foreign key that references Class.class_id. It links each student to the class record without repeating class details in every student record.

For a normalisation question:

Identify repeated or dependent data, split it into suitable tables, and keep foreign keys to reconnect related records.

Common Mistakes

  • Choosing a field such as name as primary key even though names may repeat.
  • Storing the same tutor name in many student records.
  • Splitting tables without keeping foreign keys to reconnect the data.
  • Treating a many-to-many relationship as if it can be represented by one foreign key.
  • Saying a table is in 3NF without checking dependencies.
  • Forgetting that a linking table can represent a relationship, not just an object.
  • Thinking that normalisation removes the need for joins. Normalisation often makes joins necessary.

Check Your Understanding

  1. What is a primary key?
  2. What is a foreign key?
  3. Why is repeated tutor data a problem?
  4. Why might Loan(student_id, book_id, loan_date) use a composite key?
  5. Why is Student(student_id, student_name, class_id, tutor) not a good 3NF design if class_id -> tutor?
  6. Why does a many-to-many relationship usually need a linking table?

Answers:

  1. A field or fields that uniquely identify a record in a table.
  2. A field that references a primary key in another table.
  3. It can cause inconsistent updates and unnecessary duplication.
  4. A loan record may be identified by the combination of student and book only if that combination is unique under the design assumptions.
  5. Because tutor depends on class_id, which is a non-key field in Student; tutor should be stored in Class.
  6. Because one record on each side can be related to many records on the other side. A linking table stores each specific relationship as a separate record.