Primary key

The column or columns that uniquely identify each row. It is NOT NULL and unique, and in InnoDB it also decides the physical order of the table on disk, because the table itself is stored as an index on the primary key.

Minimal example

sql
CREATE TABLE item_sizes (
  item_id     BIGINT UNSIGNED NOT NULL,
  size        VARCHAR(8)      NOT NULL,
  price_paise INT UNSIGNED    NOT NULL,
  PRIMARY KEY (item_id, size)
);

Learn this concept

Lesson 2.1 · MySQL tables, keys and InnoDB indexes

Used in exercises

Exercise 2.3 · Write the restaurant and menu migrations Exercise 3.6 · Migration 0006: order tables