Ad Banner Placeholder

Cambridge IGCSE Computer Science · 0478

Topic 9: Databases — Part 3

Primary Keys

Primary keys

A primary key is a field (or combination of fields) that provides a unique identifier for each record in a table. No two records in the same table can share the same primary key value — every record must be distinguishable from every other.

The purpose of a primary key is to:

  • Uniquely identify each record so it can be found, updated, or deleted accurately
  • Link tables in a relational database — another table stores the primary key value as a foreign key to create a relationship
  • Protect data integrity by preventing duplicate records

A field can only be chosen as a primary key if it meets these selection criteria:

  • The value must be unique for every record
  • The value must never change for a given record (it should permanently identify that record)
  • The value must always be present — it cannot be blank or NULL

Consider a library Books table. Which fields are suitable as a primary key?

ISBN (PK) BookTitle Author Genre
978-0141 1984 George Orwell Sci-Fi
978-0142 1984 George Orwell Sci-Fi
978-0743 Dune Frank Herbert Sci-Fi
978-0744 Foundation Isaac Asimov Sci-Fi
Field Suitable as PK? Reason
BookTitle No Multiple copies of the same book share the same title — values are not unique
Author No One author may have written many books in the library — values are not unique
Genre No Many books belong to the same genre — values are not unique
ISBN Yes Each book edition has a unique International Standard Book Number that never repeats

If no existing field in a table is unique, you must add a new field specifically to serve as the primary key — for example, an auto-incrementing MemberID in a library members table where names and addresses could be duplicated.

0/15

Ad Banner Placeholder