Natural keys: decide when a business identifier can be a primary key
Learn how to evaluate a meaningful business identifier for uniqueness, scope, presence, and stability before using it as a database key.
Natural keys: decide when a business identifier can be a primary key
A natural key is a value or combination that already identifies something in the business, such as an employee number, product code, or customer number from a source system. Meaning alone does not make it a good database primary key. Check that it is unique, required, unambiguous in scope, and stable over time. If it is not, use an internal surrogate primary key and preserve the business rule with a separate constraint.
Natural, candidate, and primary keys
“Natural key” describes where an identifier comes from and why it matters. A candidate key is a minimal set of columns that can uniquely identify a row. A primary key is the candidate chosen as the table’s main identifier. Therefore, a natural key is not automatically the primary key: it can be selected as the primary key, or a surrogate can be the primary key while the natural key has a UNIQUE constraint.
For example, a company-issued customer number might be a candidate if it exists for every customer, never changes, and is unique across all regions. Email is a weaker assumption: a person may change it, share it with a family account, or lose it so it can later be assigned elsewhere. The actual service rules decide whether it can be a dependable identifier.
Four checks for a natural-key candidate
**What is its uniqueness scope?** Is the value unique across the whole system, or only within a company, country, or source? If uniqueness is scoped, include the scope columns in the key and constraint.
**Is it required for every row?** If identifiers can be missing or provisional, decide how `NULL` and duplicates behave. Use `NOT NULL` when the business rule requires a value.
**Will it remain stable?** Attributes of people, organizations, and products can change or be reused. If foreign keys refer directly to a mutable value, changes can ripple through related rows and integrations.
**Is it minimal?** A composite key needs all columns that define identity, but adding unrelated attributes enlarges the key and every foreign key that references it, and couples unrelated rules.
A meaningful key is not secret and does not prove authorization. Also agree across systems on formatting rules such as case, spaces, and normalization.
Example: customer numbers from multiple sources
Hypothetical example: Two customer systems both issue the number C-104. Using customer_number alone as the key of a combined table cannot distinguish them. If a number is unique only within its source system, (source_system, customer_number) is a natural composite candidate key.
CREATE TABLE imported_customers (
source_system text NOT NULL,
customer_number text NOT NULL,
email text,
PRIMARY KEY (source_system, customer_number)
);This assumes the source-and-number pair is unique and stable. If a source reuses numbers or changes its rules, the pair no longer identifies a record over time. One option is an internal customer_id primary key plus a separate uniqueness constraint on the current source key; another is to model the source record’s validity period. Also consider the cost of repeating every composite-key column in child-table foreign keys.
Natural primary key or surrogate primary key?
| Situation | Natural primary key may fit | Surrogate primary key plus natural-key constraint may fit |
|---|---|---|
| Value is required, unique, stable, and used as-is by related systems | The business identity can be explicit in the schema | A surrogate may still simplify references |
| Value can change, be reused, or collide across sources | Use caution | Internal references stay stable while business/source values are managed separately |
| Identity spans many columns and many child tables reference it | Consider composite-FK cost | A single-column key can simplify references |
| Identifier is missing or its issuing rule is uncertain | Poor candidate | Internal identity can be separated from provisional/source identifiers |
Neither choice is always better. A natural primary key makes business identity explicit and can prevent duplicates, but changes may affect every reference. A surrogate stabilizes internal references but does not prevent business duplicates; keep the natural-key rule in a separate UNIQUE and, when required, NOT NULL constraint. PostgreSQL’s handling of NULLs in unique constraints can differ from other DBMSs, so verify behavior when portability matters.
Apply and verify the rule
PostgreSQL requires a primary key to be unique and non-null and supports composite primary keys. A UNIQUE constraint prevents duplicate values or combinations. These PostgreSQL examples are illustrative and were not run:
-- Use the natural composite key as the primary key
CREATE TABLE customers_by_source (
source_system text NOT NULL,
source_customer_number text NOT NULL,
name text NOT NULL,
PRIMARY KEY (source_system, source_customer_number)
);
-- Use an internal key while preserving the natural-key rule
CREATE TABLE customers_internal (
customer_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
source_system text NOT NULL,
source_customer_number text NOT NULL,
name text NOT NULL,
UNIQUE (source_system, source_customer_number)
);Before adding a constraint to real data, inspect duplicates, missing values, reuse scope, and case/space rules. Classify conflicts and agree with the data owner on the authoritative record before cleanup; deleting or merging rows blindly can misdirect references. After a change, verify in a test environment that duplicate inserts, key changes, and foreign-key references are accepted or rejected as intended.
Ask separately whether a value is meaningful and whether it is a dependable long-term identifier. Then decide which rule belongs in the primary key and which should remain a separate uniqueness constraint.
Sources
[PostgreSQL 18: Constraints — UNIQUE and primary keys](https://www.postgresql.org/docs/18/ddl-constraints.html)
[Microsoft Learn: Natural and surrogate keys in Fabric dimension tables](https://learn.microsoft.com/fabric/data-warehouse/dimensional-modeling-dimension-tables)
Documentation checked 2026-11-23. SQL is illustrative PostgreSQL syntax and was not executed. Constraint details can vary by DBMS.