Software Engineering › Learn step by step › Y12 Programming for the Web
Item 289 of 426 · Year 12: Programming for the Web, 55 of 59
Primary key and foreign key
Code pattern
Jump to a topic
- Exam format, question types and command words (46)
- Year 11: Programming Fundamentals (69)
- Year 11: The Object-Oriented Paradigm (33)
- Year 11: Programming Mechatronics (29)
- Year 12: Secure Software Architecture (57)
- Year 12: Programming for the Web (59)
- Year 12: Software Automation (35)
- Year 12: The Software Engineering Project (47)
- Diagrams and modelling tools (18)
- Python, SQL, pseudocode and CSS patterns (33)
Definition
A primary key uniquely identifies each record in a table; a foreign key is a field that holds another table's primary key to link the tables.
Example: ClassID is the primary key of Class and a foreign key in Student.
Found in: course specifications, school notes.
Where you'll use it in the test
Syllabus area: Y12 Programming for the Web.
Question types it can appear in
- Multiple choice: Pick the option that matches the definition or example.
- Fill in the blanks: Choose this term to complete a statement or table.
- Drawing: ERD
- SQL: Write or read it in the SQL query tool.
Where it has appeared in the paper
Programming for the Web (Part C); The Software Engineering Project (Part A). Part letters follow each paper’s own layout.
Related past questions
- Familiarisation Q12b (3 marks): SQL (joins, AS) Programming for the Web (Part C) · 3 marks
- 2025 HSC Q15a (3 marks): Data dictionary The Software Engineering Project (Part A) · 3 marks
How to use it
A model sentence
Code pattern: “A primary key uniquely identifies each record in a table; a foreign key is a field that holds another table's primary key to link the tables.” Then apply it: ClassID is the primary key of Class and a foreign key in Student.
In a short answer, give the definition in your own words first, then tie it to the situation in the question. Do not copy the example above unless it fits the scenario.
Official worked answer
Familiarisation Q12b (3 marks): SQL (joins, AS) (3 marks): official criteria and sample answer
Criteria
3: Correct SQL query. 2: Substantially correct query with at least TWO of: renaming the columns; selecting the three tables; joining the tables. 1: Some understanding of renaming the columns or joining the tables.
Sample answer
SELECT Customers.CustName as 'Customer', Products.ProductName as 'Product', Orders.OrderQuantity as 'Quantity' FROM Products, Customers, Orders WHERE Orders.ProductID = Products.ProductID AND Orders.CustID = Customers.CustID ORDER BY Orders.OrderID ASC
Go deeper
- Flashcard: Primary key and foreign key in Programming for the Web (Year 12) · study that set
- Memorise: SQL vs ORM
- Full term page: every question, note and marking comment for Primary key and foreign key
Check yourself
Write or say the “Primary key and foreign key” pattern from memory: the syntax and what it does.
Reveal the answer
A primary key uniquely identifies each record in a table; a foreign key is a field that holds another table's primary key to link the tables.
Example: ClassID is the primary key of Class and a foreign key in Student.
Could be tested as: Multiple choice, Fill in the blanks, Drawing, SQL.