Foreign key and table relationships
A field in one table that holds the primary key value of a record in another table, linking the two tables together so related data is stored once and not repeated.
Understanding Foreign key and table relationships in VCE Spreadsheets, SQL & Visualisation
What it does: The foreign key class_id sits on the many side (Students) and points to the one side (Classes). A foreign key stores the primary key value from another table. This is what links the two tables together. A foreign key must match an existing primary key. ClassID 9 does not exist in Classes, so it is not valid. The teacher's name is stored once in Classes. Students link to it by ClassID, so one change is enough. Repeating class details for each student wastes space and causes errors when one copy is changed. A foreign key avoids this.
Common mistakes: The keywords are in the wrong order. The statement must start with CREATE TABLE and then the table name: CREATE TABLE Classes (. ClassID has lost its PRIMARY KEY. A foreign key in Students can only link to a primary key in Classes. It should be: ClassID INT PRIMARY KEY.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 35–44) and word search (Modules 35–54).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
FOREIGN KEYFill in the Blanks
Spot the Error
Student with a class code? Join your class →