Relational Databases & Normalisation Grade 12

A relational database stores data in structured tables linked together. Normalisation is the process of cleaning up a database design to remove repetition and prevent errors.

What is a Relational Database?

A relational database stores data in tables (also called relations). Each table represents one type of thing — for example, a table for students, a separate table for subjects. Tables are then linked together using key fields.

tblStudents StudentID Name ClassID 🔑 1 Alice C01 2 Bob C02 3 Carol C01 PK: StudentID FK: ClassID → tblClasses FK links to PK tblClasses ClassID ClassName 🔑 C01 12A C02 12B PK: ClassID

Key Fields

Key TypeDescriptionExample
Primary Key (PK)Uniquely identifies each record. No duplicates, no blanks.StudentID in tblStudents
Foreign Key (FK)A field that links to the primary key of another table. Creates the relationship.ClassID in tblStudents → links to tblClasses
Composite KeyTwo or more fields combined to create a unique identifierStudentID + SubjectID in tblMarks
Alternate KeyCould be a primary key but wasn't chosen as oneEmail address (also unique, but ID was chosen as PK)

Referential Integrity

Referential integrity is a rule that ensures relationships between tables remain consistent. It means: a foreign key value must always match an existing primary key value in the related table.

Example of violating referential integrity

If ClassID C03 doesn't exist in tblClasses, you cannot add a student with ClassID = C03. The database will reject this to prevent orphan records (records with no matching parent).

Entity Relationship Diagram (ERD)

An ERD is a diagram that shows the entities (tables) in a database and the relationships between them. Each box is a table; the line between boxes shows how they relate. You are often asked to draw one in the exam, so practise the crow's-foot notation below.

tblBooks BookID (PK) Title Author Genre 1 tblLoans LoanID (PK) BookID (FK) DateBorrowed DateReturned

The relationship is created by putting the primary key of the "one" table into the "many" table as a foreign key (here BookID links tblBooks to tblLoans).

Types of Relationships

RelationshipMeaningExample
One-to-One (1:1)One record links to exactly one record in the other tableOne person ↔ one ID number
One-to-Many (1:∞)One record links to many records in the other tableOne book can appear in many loans
Many-to-Many (∞:∞)Many records link to many records — resolved with a third "link" tableStudents ↔ Activities (via a link table)
Many-to-many needs a link table

A relational database can't store a many-to-many relationship directly. You break it into two one-to-many relationships using a junction/link table (e.g. tblLoans links books and borrowers).

Physical vs Logical Integrity

TypeWhat it protectsHow it is ensured
Physical integrityThe data is not lost or damaged by hardware failure, power loss or disasterRAID, UPS, regular backups, off-site storage
Logical integrityThe data stays correct, consistent and valid within the databaseValidation rules, referential integrity, record locking
Record locking

Record locking temporarily "locks" a record while one user is editing it, so that a second user cannot change the same record at the same time. This prevents two users overwriting each other's changes and keeps the data consistent (a key way to protect logical integrity in a multi-user database).

Database Anomalies

When a database is poorly designed (not normalised), three types of errors can occur when working with data:

AnomalyWhen it happensExample
Insertion anomalyYou can't add new data without first adding other unrelated dataCan't add a new class until at least one student enrols in it
Deletion anomalyDeleting one record accidentally removes other important dataDeleting the only student in a class also deletes the class's information
Modification anomalyChanging one value means updating many rows — and missing some creates inconsistencyA teacher's name appears in 50 student records; update one and the others are wrong
The fix: Normalisation

Normalisation splits large, messy tables into smaller, focused tables and links them properly. This eliminates all three anomalies.

Normalisation — The Three Normal Forms

First Normal Form (1NF)

A table is in 1NF when:

Not in 1NF:

StudentIDNameSubjects
1AliceMaths, IT, English

❌ Problem: Three values in one cell (Subjects column)

In 1NF:

StudentIDNameSubject
1AliceMaths
1AliceIT
1AliceEnglish

Second Normal Form (2NF)

A table is in 2NF when it is in 1NF AND every non-key field depends on the whole primary key (not just part of it). This only matters when the primary key is a composite key.

Example violation:

StudentID (PK)SubjectID (PK)StudentNameMark
1ITAlice85

❌ Problem: StudentName only depends on StudentID, not on (StudentID + SubjectID) together

In 2NF — split the table:

StudentID (PK)StudentName
1Alice
StudentID (PK+FK)SubjectID (PK)Mark
1IT85

Third Normal Form (3NF)

A table is in 3NF when it is in 2NF AND no non-key field depends on another non-key field (no transitive dependency).

Example violation:

StudentID (PK)NameGradeLevelGradeDescription
1Alice12Matric

❌ Problem: GradeDescription depends on GradeLevel (a non-key field), not on StudentID

In 3NF — split it:

StudentID (PK)NameGradeLevel (FK)
1Alice12
GradeLevel (PK)GradeDescription
12Matric

Quick Normalisation Checklist

Normal FormCheck forFix by
1NFMultiple values in one cell? Repeating columns?Split into separate rows; add PK
2NFNon-key field depends on only PART of the composite PK?Move that field to its own table
3NFNon-key field depends on another non-key field?Move the dependency to its own table

Good Database Characteristics

CharacteristicMeaning
Data integrityData is accurate, consistent and complete throughout its lifecycle
Data independenceChanging the database structure doesn't break the programs that use it
Data redundancyMinimum — the same data should not be stored in multiple places
Data securityOnly authorised users can access or modify data
Ease of maintenanceThe database design makes it simple to insert, update and delete without causing problems