Primary key
Definition
A primary key is a unique, non-null identifier for each row of a table, and a foreign key is a column whose values must match a primary key in another table.
In practice
Primary keys give every row a stable identity for updates, joins and references; foreign keys let the database reject orphans, such as an order for a customer that does not exist, for every writer. Both are backed by indexes for primary keys, but most databases do not automatically index the foreign key column, which is a frequent cause of slow joins and deletes.
Surrogate keys (sequences, UUIDs) are stable and short; natural keys like email addresses change and leak meaning. UUIDv4 primary keys spread inserts randomly across the index, while UUIDv7 or sequences stay time-ordered. Sharded systems often drop foreign keys across shards because the database can no longer check them.
Example
orders.customer_id REFERENCES customers(id) makes the database reject an order for customer 999 if no such customer exists, and an index on orders(customer_id) keeps the join fast.