Related tables and keys
About this lesson: Related tables and keys
In short
Putting students and their results in one table repeats names and classes in many rows. Look at the problems this causes.

What you'll explore
- One big table: What goes wrong?
- Putting students and their results in one table repeats names and classes in many rows. Look at the problems this causes.
- Two related tables: Link with a key
- Split the data into Students and Results. StudentID links them. Choose a student to see which results belong to them.
- Keys: Primary and foreign
- A primary key identifies each record. A foreign key holds another table's primary key, creating the link.
- Check yourself: Foreign key
- A Loans table records which library member borrowed each book. It has LoanID, MemberID and BookID.
Also in this lesson
- Common mix-ups
- Students and Results
- Library cards
Words to know
- relational database
- A database of tables linked by keys.
- record
- One row: all the data about one item.
- field
- One column: one kind of data.
- primary key
- A field that is unique for each record.
- foreign key
- A field that links to another table's primary key.
Sources
- BBC Bitesize KS3 Computer Science
- Raspberry Pi Foundation, Computing curriculum resources