Disclosure: I build Schemity, a desktop ERD tool - this post is from our blog and uses it for the examples.

TL;DR: Point foreign keys at a surrogate id whenever the natural value can change, which covers SKUs, emails, usernames and product codes, and keep the natural value UNIQUE on its own table. A natural-key foreign key turns every rename into a rewrite of the child rows, including history that should have kept the old value. A natural key is a reasonable target only for a short, stable standard code, such as an ISO country or currency code. On MySQL a string foreign key must also share the referenced column's collation exactly.

A foreign key should reference a surrogate key, a generated id, unless the natural value is a short code that never changes, because a foreign key copies the referenced value into every child row. Reference products.sku and each order line holds the SKU; rename the SKU and every order line has to change with it, or the database refuses the rename. Reference products.id and the SKU is free to change, since only the products row holds it.

The question is usually asked as natural key vs surrogate key, but the decision that costs something is the one about foreign keys. Everything below ran on PostgreSQL 18.3 and MySQL 8.4.11 in throwaway containers, with 10,000 products and 1,000,000 order lines in each child table. PostgreSQL does not index a foreign key column by itself, so the indexes are created here; MySQL creates them on its own.

CREATE TABLE products ( id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, sku text NOT NULL UNIQUE, name text NOT NULL ); CREATE TABLE order_items_by_sku ( id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, sku text NOT NULL REFERENCES products (sku) ON UPDATE CASCADE, quantity int NOT NULL ); CREATE TABLE order_items_by_id ( id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, product_id bigint NOT NULL REFERENCES products (id), quantity int NOT NULL ); CREATE INDEX ON order_items_by_sku (sku); CREATE INDEX ON order_items_by_id (product_id); 

What is the difference between a natural key and a surrogate key?

A natural key is a value the business already uses to identify a row, such as a SKU, an email or an ISO country code; a surrogate key is a value the database makes up for the purpose, such as an identity or a UUID.

Both identify the row, and both can be enforced unique. The difference is who controls the value. Nobody outside the database cares what products.id is, so it never needs to change. The SKU belongs to merchandising, the email belongs to the user, and the product code belongs to a supplier. Any of them can decide it is wrong.

What does a natural-key foreign key cost when the value changes?

Every child row that holds the old value has to be rewritten, history included, and without ON UPDATE CASCADE the change is refused.

With a plain foreign key, renaming a SKU that one row uses fails:

CREATE TABLE lines_plain (id int PRIMARY KEY, sku text NOT NULL REFERENCES products (sku)); INSERT INTO lines_plain VALUES (1, 'ACME-MUG-000002'); UPDATE products SET sku = 'ACME-CUP-000002' WHERE sku = 'ACME-MUG-000002'; 
ERROR: update or delete on table "products" violates foreign key constraint "lines_plain_sku_fkey" on table "lines_plain" DETAIL: Key (sku)=(ACME-MUG-000002) is still referenced from table "lines_plain". 

Updating the child first fails the same way, the other way round. The ways around it are inserting the product again under its new SKU, repointing the children and deleting the old row, or declaring the key DEFERRABLE so both updates can land in one transaction.

With ON UPDATE CASCADE, PostgreSQL rewrites the children for you. Renaming one SKU with 100 order lines took 3 ms. Then the company rebranded: UPDATE products SET sku = replace(sku, 'ACME-', 'NOVA-') renamed all 10,000 SKUs, and the cascade rewrote all 1,000,000 order lines. It took 22 seconds and doubled order_items_by_sku from 57 MB to 115 MB until a vacuum, because PostgreSQL writes a new version of every row it updates. On order_items_by_id, the same rebrand touches no order line at all.

The cost that matters more is what the cascade did to the history. An order line from last year now says NOVA-MUG-000001, a SKU that did not exist when the customer bought the mug, and every invoice or export rebuilt from it says the same. Schemas that need the SKU as sold keep a copy of it on the order line, with no foreign key, next to a product_id that points at the product as it is now.

Are text foreign keys bigger or slower than integer ones?

Less than people expect: on PostgreSQL 18.3 the index on 1,000,000 text foreign keys was 7.3 MB against 6.7 MB for bigint.

A btree index stores each repeated value once (deduplication, since PostgreSQL 13), so 1,000,000 order lines over 10,000 SKUs cost little more than the same lines over 10,000 ids. The tables differed by 7 MB, 57 MB against 50 MB, for SKUs like ACME-MUG-000001. Longer values, such as email addresses or composite natural keys, widen that gap. But storage is rarely the reason to choose. The reason is what happens when the value changes.

What does MySQL add to a string foreign key?

MySQL compares a string foreign key under its collation, so the two columns must share one exactly, and a case-insensitive collation lets values match that your code thinks are different.

Each row below is a child table with sku referencing products.sku VARCHAR(40), created under MySQL 8.4's default collation, utf8mb4_0900_ai_ci:

Child column, or the row inserted MySQL 8.4.11
VARCHAR(40) COLLATE utf8mb4_bin Refused, error 3780, ... are incompatible
VARCHAR(40) CHARACTER SET latin1 Refused, error 3780
VARCHAR(20), same collation Accepted, but a rename to a SKU over 20 characters is refused, error 1451
A row holding acme-mug-01 Accepted: it references ACME-MUG-01
A row holding ACME-MUG-01 with a trailing space Refused, error 1452

The fourth row is the one that bites. MySQL's default collation ignores case, so the foreign key is satisfied by acme-mug-01. A comparison that respects case, such as li.sku COLLATE utf8mb4_bin = p.sku or the same check in application code, then finds no product for that order line. The mismatch lasts until the next cascade: renaming the parent rewrote the child to the parent's exact value. A surrogate key has no collation, so none of this can happen to product_id.

Natural key vs surrogate key: which should a foreign key reference?

Reference the surrogate key, and keep the natural value unique on its own table, unless the natural value is a short standard code that does not change.

Natural value Changes? Foreign key should reference
SKU, product code Rebrands, supplier changes, typos products.id, with the SKU as sold copied onto the order line
Email, username Whenever the user wants users.id
Order number shown to customers Rarely, once issued Either; orders.id keeps joins uniform
ISO 3166 country code, ISO 4217 currency Rarely, by an outside standard The code itself, CHAR(2) or CHAR(3)
A composite natural key, such as (company_id, invoice_number) When numbering rules change A surrogate id, with the pair UNIQUE

The country code row is the honest exception. addresses.country_code = 'VN' is readable without a join, the value is short, and when the standard does change, it withdraws a code or splits one country's code into several, which is a planned data migration that no cascade could express anyway. The same reasoning fails for a SKU, because a SKU changes on a business decision, not a standards body's.

Choosing the surrogate does not mean dropping the natural key. sku text NOT NULL UNIQUE still stops two products from sharing a SKU; it is just not what other tables point at.

How do you draw a natural-key foreign key without the MySQL mismatch?

Draw the relation instead of typing the column, so the new column copies the key's type, character set and collation.

Schemity is database design software that reads your live database, shows the impact of every schema change before it runs, and keeps the diagram as a file in Git. When you design the next one, a relationship drawn from a parent creates the child's foreign key column from the parent's primary key. On a MySQL diagram where countries is keyed by code CHAR(2) CHARACTER SET ascii COLLATE ascii_bin, the relation to an empty warehouses table planned:

ALTER TABLE `warehouses` ADD COLUMN `country_code` CHAR(2) CHARACTER SET ascii COLLATE ascii_bin NOT NULL; ALTER TABLE `warehouses` ADD CONSTRAINT `warehouses_country_code_fkey` FOREIGN KEY (`country_code`) REFERENCES `countries` (`code`) ON DELETE NO ACTION ON UPDATE NO ACTION; 

Schemity's change preview on a MySQL diagram after drawing a relation from countries to warehouses: the planned migration adds warehouses.country_code CHAR(2) CHARACTER SET ascii COLLATE ascii_bin NOT NULL and the foreign key warehouses_country_code_fkey to countries (code), with two planned changes, no lint findings and the impact line Rewrites warehouses, 16 KB on disk

The column is named after the key it holds, country_code, not country_id, and it carries the key's character set and collation, the pair error 3780 checks. The same holds for a products table keyed by sku, which gives order_items.product_sku. On a table that already has rows, add the column as nullable, fill it, then set NOT NULL and add the key: MySQL fills a new NOT NULL CHAR column with '', which no country has, so the foreign key would be refused with error 1452. Before you apply it, impact analysis (a Schemity Pro feature) reports that adding the foreign key rewrites warehouses, which MySQL does while foreign key checks are on.

Writing this post found two gaps, fixed for the next release. When an AI agent added the same relation over MCP, Schemity named the column country_id whatever the parent's key was called, and ignored the diagram's naming convention; it now names it exactly as a drawn relation does. And the finding for a rewrite of a whole table, such as this one, read as an unfinished sentence.

Related reading