Skip to content
DB2 & data

Primary key

The column or columns that uniquely identify each row in a table, so no two rows share the same value.

Also written key, foreign key, unique key

A primary key is the identifier for a row. An account number identifies an account, a policy number a policy. The database enforces that the value is unique and present in every row, so duplicates cannot be created even by mistake.

It is usually supported by a unique index, which both enforces the rule and makes lookups by key fast, which is convenient, because looking a row up by its key is the most common thing any application does.

Keys can be made of more than one column when a single value is not enough to identify a row, such as an account number plus a transaction date and sequence number.

Primary keys are also the anchor for relationships. A foreign key in another table holds the primary key value of the row it relates to, and the database can enforce that the reference points at something real, preventing transactions belonging to accounts that do not exist.

The same idea appears in VSAM, where a KSDS record has a unique key used to retrieve it directly.

Browse all 115 terms

Learn this properly.

Use Primary key for real in Mainframe101, in your browser, with Zed beside you. Join the waitlist.

Early access and updates. No spam, unsubscribe any time.