Form 4 · Chapter 2

Relational Database Design

Good design uses primary keys and foreign keys to link tables, and reduces redundancy through the basics of normalisation.

Primary Keys and Foreign Keys

A primary key is a field (or a combination of fields) that uniquely identifies each record in a table. Its value cannot be repeated and cannot be empty. For example, StudentNo is a good primary key because every student has a different number.

A foreign key is a field in one table that refers to the primary key of another table. The foreign key is what creates a relationship between two tables and lets data be linked without being copied.

Key idea

A primary key uniquely identifies each record in a table. A foreign key is a field that refers to the primary key of another table to form a relationship.

Relationships and the ER Diagram

Relationships between tables can be one-to-one, one-to-many or many-to-many. One-to-many is the most common, for example one student can have many book-loan records.

An entity relationship diagram (ER diagram) is a diagram that models the entities (tables), attributes (fields) and the relationships between them. Entities are usually drawn as rectangles, and relationships are shown by lines connecting the entities.

Example

A Student table (primary key StudentNo) and a Loan table that has StudentNo as a foreign key. One student (one record) can appear in many loan records — a one-to-many relationship.

Avoiding Redundancy and Normalisation

Normalisation is the process of arranging fields and tables to reduce data redundancy and avoid anomalies when inserting, updating or deleting data. The basic idea is that each fact is stored only once, and tables are split so that every field depends only on its primary key.

Remember

Primary key = unique and not empty. Foreign key = the link to another table. Normalisation = reduce redundancy so the data stays accurate.

Stuck on this topic? A verified JomKelas tutor can walk you through it.

Find a verified tutor