🌱

Keys in Data Warehousing

Master surrogate, natural, and business keys.

Section 1 of 3: Types of Keys0%

Types of Keys

Study Material

Understanding Different Key Types:

Keys are fundamental to data modeling. Using the right key strategy is critical for data warehouse success.

1. Natural Key (Business Key) 🏢

A meaningful identifier that comes from the business domain.

Examples:

  • Social Security Number
  • Email address
  • Product SKU
  • Employee ID (from HR system)
  • Invoice number

Pros:

  • Business meaning - users understand it
  • No lookup needed to understand data
  • Exists in source systems

Cons:

  • Can change (email updates, company rebranding)
  • May be recycled (employee ID reused)
  • Can be composite (harder to JOIN)
  • May contain sensitive data (SSN)

2. Surrogate Key 🔢

A system-generated, meaningless identifier created by the data warehouse.

Examples:

  • customer_key: 1, 2, 3, 4...
  • product_key: 10001, 10002...
  • Auto-incrementing integers or UUIDs

Pros:

  • Immutable - never changes
  • Simple - single integer column
  • Efficient JOINs - integer comparison fast
  • Supports SCD Type 2 (multiple versions)
  • No sensitive data exposure

Cons:

  • No business meaning
  • Requires lookup to find natural key
  • Additional column in every table

3. Primary Key 🔑

Uniquely identifies each row in a table. Can be either natural or surrogate.

4. Foreign Key 🔗

References the primary key of another table. Creates relationships.

5. Composite Key 🧩

Multiple columns together form a unique identifier.

Example: (order_id, product_id) in order_items table

Data Warehouse Best Practice:

Table TypeKey Strategy
Fact TablesSurrogate key (optional), plus FKs to dimensions
Dimension TablesSurrogate key (PK) + Natural key (for lookups)
Staging TablesNatural keys from source