Skip main navigation

Primary keys

Describes the importance of primary keys and their use in searching data.

Every table in a DBMS should have one field that uniquely identifies each record. A table containing products might use a product number to identify each record. The product number is unique to the product. When you search for a product using its unique product number, only the specific product you are searching for should be returned.

Computer sales database

In your computer sales database, the manufacturer_id is the primary key in the manufacturer table, model_id is the primary key in the model table, and sale_id is the primary key in the sales table. The primary keys are used to refer to a specific record within a table.

Without a primary key, updating or deleting specific records in a table becomes difficult, because there is no specific way to refer to the records you want to delete or update. For example, if you were keeping track of stock and you had two identical computers for sale, each computer would need a separate record so that you could track the sale of each one.

The primary key field can be created or selected from an existing field as long as it meets the conditions below:

  • No two records can have the same primary key data
  • The primary key value should never be re-used; if a record is deleted from the table, it should not be allocated to a new record
  • A primary key value must not be modified once it has been created
  • A primary key must have a value; it cannot be NULL


The primary key also acts as a reference to the record and offers a simple way for the DBMS to search, sort, and access the records.

If you receive a customer enquiry about a Raspberry Pi computer, some of the questions you may ask are:

  • Do you know the model number you are looking for?
  • What CPU speed would you like?
  • Is there a minimum number of cores you would like?
  • Would you like WiFi?

It would be far quicker if the customer gave you the model_id number. You can then be very precise about the model (the record) it returns.

Next steps

In previous steps, you have learnt how to search a database using SQL statements, and how to use operators for more advanced searching. If you had any problems with the quiz in the previous step, use the comments section below to ask for help.

In this step, you also started to learn about the importance of primary keys within tables; there will be more on this topic in later steps.

In the next steps you will learn about how to use SQL statements to change the data within your computer sales database.

This article is from the free online

Introduction to Databases and SQL

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education