Primary Key (Primary Keyword)

46 Computer Science Topics

We’ve created 46 modules covering every Computer Science topic needed for GCSE level. These are transferable across AQA, CIE, Edexcel, CIE & Internationally. Suitable for teachers or home educators alike.

Whether you’re a brand new Computer Science teacher, or you’ve been teaching ICT for years, our resources will save you hours and hours of lesson preparation every single week.

View the resources →

A primary key, also known as primary keyword, is a key in a relational database which is specific for each record.  It is a unique attribute, like a driver’s license number, telephone number with area code, or vehicle identification number (VIN).  A relational database can only have one primary key.  Primary keys are usually displayed as columns in relational database tables.

The choice of a primary key in a relational database often comes down to the preference of the administrator.  The primary key for a given database can change when the specific needs of the users change.  For example, the people in a town might be uniquely identified based on their driver’s license numbers in one application, but in another situation, it might be more appropriate to identify them based on their telephone numbers.

A primary key is a distinct identifier for a database record.  One of the fields is typically assigned as the primary key once a table is created.  While the primary key is often a number, a text field (or other data type) may also be assigned as a primary key.  For example, if a database contains definitions of computer terms, it would make sense for each term to only be listed once in the database.  By defining the “Term” field as the primary key, it would effectively guarantee that no term is listed more than once in the database.

While a table’s primary key is usually assigned to a specific field, it can also be composed of multiple values.  For example, a database of news articles can utilise both the title and date fields to distinguish each entry.  By combining the “Title” and “Date” fields as the primary key, it would ensure that no entries have the same title on the same day, which is crucial when it comes to organisation of the database.

If several fields in a table cannot have identical values, most database management system (DBMS) also allow fields to be marked as “Unique.”  This is similar to setting a field as the primary key, but isn’t quite the same thing.  The primary key also acts as an indicator to the record and offers a simple way for the DBMS to search through, sort, and access the records.  Additionally, it helps to connect records across multiple tables.  Therefore, while multiple fields within a table can be defined as “Unique,” each table can only have one primary key.  The primary key field must be established for each record, and cannot be null.  After all, an undefined identifier is not very useful.

A primary key is either a special relational database table column, or a combination of columns selected to uniquely identify all table records.

Main Features of Primary Key

  • It must contain a unique value for each row of data.
  • It cannot contain null values.

A primary key is either an existing table column or a column that is specifically made by the database, in accordance with a defined sequence.

The primary key concept is an important aspect to any efficient relational database.  Relational databases would not work without primary key—and the closely related foreign key—concepts.

Almost everyone deals with primary keys frequently but unknowingly in everyday life.  For example, students are routinely assigned unique identification (ID) numbers, and citizens of a country have unique government-assigned IDs.

Take as an example a database which must contain all of the data stored by a commercial bank.  The best option is to create a separate primary key in a new column named CUSTOMER_ID.  The database automatically generates a unique number each time a customer is added, ensuring a consistent pattern unique identification.  As this key is created, the column is assigned as the primary key within the SQL script that creates the table, and all null values are automatically rejected.