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.
Related terms
- IndexA structure that lets a database find rows by value without reading the whole table.
- SQLThe language used to query and change relational data. The same SQL used everywhere else, running against mainframe tables.
- DB2 for z/OSIBM's relational database on the mainframe, where a great deal of the world's banking and insurance data is stored.
- KSDSThe most common VSAM dataset type, where every record has a unique key used to find it directly.
- VSAMA family of dataset types built for fast record access by key, used where applications need to look records up rather than read them in order.