Primary Key

A primary key is a unique identifier value for a database record in a table. It is typically a number, often generated sequentially as the database creates new records, but text strings may also be used as primary keys if they are guaranteed to be unique. Relational databases use primary keys to create links between records across separate tables.

When you create a table, you have several options for assigning primary keys. First, you may choose a primary key from existing information in the record, like a customer phone number or Social Security Number; this kind of primary key is called a "natural key." A "surrogate key," on the other hand, is a value generated solely to serve as the primary key. A DBMS can generate a surrogate key sequentially as it adds new records, or generate a random number or UUID instead. If a DMBS must delete a record, it usually preserves that record's primary key and will not reuse it.

Relational databases use primary keys to ensure that each record in a table is unique and to create links between records across tables. For example, a customer database could include a Customer Identification table with names and email addresses, and another Shipping Address table with street addresses. The Customer Identification table might use a generated UUID in the Customer ID field as a primary key, allowing customers to update their name without changing how the DBMS references that record. The Shipping Address table, meanwhile, saves every shipping address in the system as a separate record with a sequential ID number that increments with each new address. This allows a record in the Customer Identification table to associate each customer record with one or more addresses, using the primary key from the address table as a foreign key within a customer record.

Updated December 18, 2023 by Brian P.

quizTest Your Knowledge

What practice distributes work across several servers to keep one from being overworked?

A
Power management
0%
B
Load balancing
0%
C
Data mining
0%
D
Machine learning
0%
Correct! Incorrect!     View the Load Balancing definition.
More Quizzes →

The Tech Terms Computer Dictionary

The definition of Primary Key on this page is an original definition written by the TechTerms.com team. If you would like to reference this page or cite this definition, please use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about this definition or would like to suggest a new technical term, please contact us.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.