Data engineering and IT

Foreign key

  • Data engineering and IT

Definition

A column in one table whose values must match the primary key of another table, so the two tables stay correctly linked.

Example

In Raket Parts B.V. data, sales_orders.customer_ref is a foreign key to customers.customer_ref. All 7,235 orders point to one of the 436 customers, with no orphan orders. A database can enforce this, refusing an order for a customer who does not exist.

Raket Parts B.V. is a fictional company created for Insyt.

See how it works

Parent tablecustomers.customer_id
Referencing tableorders.customer_id

The matching values link the two tables. Some systems enforce referential integrity; other analytical stores may not.

Check your understanding

Common mistake: A matching column name does not by itself establish a valid or enforced foreign-key relationship.

What can happen if an order references a customer that does not exist?

Show explanation

It creates an orphan reference unless an enforced constraint prevents the write.

For your role

Choose your role to see what this term means in your work.

Why it matters

It keeps related data consistent and tells you which columns to join on.

Where it is used

Database design and data model relationships. Used by data engineers, BI developers and data analysts.