---
title: "Relational Databases: Tables, Keys and Relationships"
description: "A relational database stores records in tables. Primary keys identify rows, and foreign keys refer to unique keys in the same table or another table. Relationships describe how records connect."
canonical: https://lightmysky.com/learn/computing/relational-databases-tables-keys-and-relationships-mt_i7pZV6H902
source: https://lightmysky.com/learn/computing/relational-databases-tables-keys-and-relationships-mt_i7pZV6H902.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Relational Databases: Tables, Keys and Relationships

A relational database stores records in tables. Primary keys identify rows, and foreign keys refer to unique keys in the same table or another table. Relationships describe how records connect.

Subject: Computing · Area: Computer Systems · Ages 17 to 18
Page: https://lightmysky.com/learn/computing/relational-databases-tables-keys-and-relationships-mt_i7pZV6H902

## Ready when they can

- Choose a primary key for a table and justify why it identifies a row
- Link two tables with a foreign key and name the relationship as one-to-many or many-to-many
- Say what goes wrong when the same fact is stored in two places

## Lesson: Tables, keys and the links between them

Tables have rows and columns. A row records one entity, such as a student, or one relationship, such as a membership. Columns hold its properties. A primary key is one column or a combination that identifies each row uniquely. No key column may be null (missing). A different ID given to every student and kept unchanged is a suitable student key. Names and favourite colours may be shared.

**Example.** Two member records hold club C8's name as Drama. A rename to Theatre changes one record but misses the other, leaving different current names for the same club. Instead, store C8's name once in Clubs and let member records refer to C8. The ID may repeat in links; the current name has one place to update. This reduces copy-update mistakes, but other errors can still occur.

*(drawing: A partial update can leave two current names for the same club.)*

A foreign key is one column or a set of columns that refers to a unique key in the same table or another table. Here, Memberships.StudentID refers to the primary key Students.StudentID. With the constraint enforced, a non-null membership StudentID must match an existing student. This column may allow null if the student link is optional.

Relationship types describe what the design allows, not just today's rows. If each book has one author and an author may have several books, Authors to Books is one to many. Books holds the author key as a foreign key. If a student may join several clubs and a club may have several students, Students to Clubs is many to many.

Students has StudentID, Clubs has ClubID, and Memberships has one row per student-club pair. Memberships.StudentID and Memberships.ClubID refer to the two tables' keys. Either ID alone can repeat. If each pair may occur only once and both IDs are non-null, the two columns together can be the membership's primary key. Keep student names in Students and club names in Clubs.

*(drawing: A database that supports automatic key updates can change matching foreign-key references with the key.)*

Primary keys must be unique and non-null. Stability is a design preference; a primary key can change. If an email used as a key changes, foreign keys referencing it must stay consistent. A database may update those references automatically or reject the change until it is handled. A uniquely allocated ID kept unchanged avoids key changes when an email changes. Inventing an ID alone does not make it unique.

**Recap.** Use unique, non-null primary keys. Keep changing details in one place and link rows with foreign keys. Check how many matches each side allows.

*Lesson, questions and revised flashcards written for this dataset. External records were consulted for factual checks and design study; no source prose is reproduced.*

## Practice

8 questions on this page, each with its working shown.

## Optional connections

- [Reading and Writing Files, Including CSV](https://lightmysky.com/learn/computing/reading-and-writing-files-including-csv-mt_j5qb4FdkdI)

## Opens up

- [Normalisation to Third Normal Form](https://lightmysky.com/learn/computing/normalisation-to-third-normal-form-mt_cbRXVW6KxX)
- [The Relational Model and Relational Algebra](https://lightmysky.com/learn/computing/the-relational-model-and-relational-algebra-mt_unDBd_Ug8T)
