Foreign Key

A foreign key is a column (or set of columns) that references the primary key of another table, enforcing referential integrity between related rows.

Foreign keys express relationships — an order belongs to a customer, a message to a conversation — and let the database guarantee those references stay valid. You can't insert an order for a customer that doesn't exist.

They also enable cascading behavior, such as deleting child rows when a parent is removed, and they document the data model directly in the schema.

Relational integrity through foreign keys is a major advantage of PostgreSQL over schemaless stores, where relationships must be maintained in application code.

Related terms

Foreign Key in Kolaybase

See it in practice

Kolaybase gives you PostgreSQL, auth, storage, and a REST API in minutes.

Get started