A Checklist Before Choosing a Primary Key

Every table needs a primary key, and changing it later is a chore. Before you decide, run through these checks. Each comes with a short reason, so you can explain your choice to a teacher, a reviewer or your future self.

The four must-haves

If you are considering a "natural" value

A natural key is a real-world value, such as an email address or a product code.

If any answer worries you, use a generated id instead and keep the natural value as an ordinary column with a UNIQUE rule.

If you are using a generated id

A surrogate key is a value the database creates, such as 1, 2, 3, which means nothing outside the database.

If the key is made of two columns

How other tables will use it

Before you finish

For practice, try the eight primary key scenarios.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.