Skip to content
Search

Primary key

lastmod 2026-01-21created 2026-01-213 edits

A primary key (primary key), also called a main key, is the candidate key selected and defined by the designer, only one per relation (table), as the most suitable identifier for tuples (records) in a relational database. A unique key can be seen as a set of 0–1 or more attributes. In other words, among the candidate keys (= attributes or sets of attributes) that uniquely identify the records stored in a relation, it refers to the one the designer has decided should generally be used.

Primary keys are used when a record identifier is needed by relational database management systems (RDBMS), middleware, applications, and so on. Unless a primary key must specifically be used, replacing it with another candidate key causes no problem in functionality. Therefore, the theoretical significance of the primary key is not great, but it is a concept widely used in practice. However, there is a difference in that a primary key does not allow NULL values, while a candidate key does. (If you think of the primary key as a constraint when adding or updating records, the primary key constraint can be thought of as a unique constraint with a NOT NULL constraint added.) When a relation has only one candidate key, that candidate key naturally becomes the primary key. Also, a candidate key that is not the primary key is called an alternate key (alternate key).

See also

Favorite site

author Zer0 sitemap