Primary & Foreign Keys (CIE IGCSE ICT)

Revision Note

Becci Peters

Expertise

Computer Science

Primary Keys & Foreign Keys

What is a Primary Key?

  • Each table has a primary key field which acts as a unique identifier
    • Each item of data in this field is unique
    • Duplicate data items would be blocked if they were entered into the primary key field
  • Because the items of data are unique within the primary key field they can be used to identify individual records

A Database Table Containing Customer Details


CustomerID


FirstName


LastName


DOB


PhoneNumber

1

Andrea

Bycroft

05031976

0746762883

2

Melissa

Langler

22012001

0756372892

3

Amy

George

22111988

0746372821

  • In the example customer table, the primary key would be the CustomerID because each customer’s ID is unique
  • If there was a customer with the same name they could be identified correctly using the CustomerID

Creating and Editing Keys

  • Primary key - Uniquely identifies each record in a table
  • Foreign key - Used to link two tables together. The Foreign Key in one table would be the primary key in another

unnamed-21

Creating Relationships Between Tables

  • Relational databases allow you to create relationships between different tables using primary and foreign keys

unnamed-22

What is a Foreign Key?

  • A foreign key is how we link tables together using primary keys
  • Using the table above with customer details, we'll add another table showing subscriptions that customers have
  • In this example CustomerID is a foreign key as it links with the CustomerID in the customer table above

SubscriptionID


CustomerID


SubscriptionType

1 2 Annual
2 1 Monthly
3 3 Quarterly

Exam Tip

  • If the answer to a question is the name of a field, ensure you copy it exactly from the question. The examiner is looking for an exact answer with the correct capital letters and underscores where they're included

Worked example

A systems analyst has created a new computer system to keep records in a medical centre. She has created a relational database to store the medical records of patients.

The database uses primary and foreign keys. Explain the difference between a primary key and a foreign key.

[4]

4 of:

The primary key holds unique data [1]
The primary key identifies the record [1]
The primary key can be automatically indexed [1]
Each table has one primary key whereas a table can contain several foreign keys [1]
A foreign key is used to link with the primary key of another table [1]

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Becci Peters

Author: Becci Peters

Becci has been a passionate Computing teacher for over 9 years, teaching Computing across the UK helping to engage, interest and develop confidence in the subject at all levels. Working as a Head of Department and then as an educational consultant, Becci has advised schools in England, where her role was to support and coach teachers to improve Computing teaching for all. Becci is also a senior examiner for multiple exam boards covering GCSE & A-level. She has worked as a lecturer at a university, lecturing trainee teachers for Computing.