Primary Keys in SQL — a practical guide to SQL primary key with clear examples you can reuse in real projects.
SQL Tutorial Series (7/100). Prefer one article? Read the complete SQL tutorial.
Short description
Primary keys are NOT NULL and UNIQUE. Prefer stable surrogate keys (e.g., INT AUTO_INCREMENT / UUID) when natural keys change.
Primary key
CREATE TABLE users (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(191) NOT NULL
);