PRIMARY KEY
PRIMARY KEY is a SQL statement in the Constraints category. A column or set of columns that uniquely identifies each row. Only one PK per table. Automatically creates a unique index. The syntax is column type PRIMARY KEY / CONSTRAINT pk_name PRIMARY KEY (col1, col2). It returns constraint. A typical example: CREATE TABLE users (id INT PRIMARY KEY AUTO_INCREMENT, ...); -- Or as table constraint: CREATE TABLE orders (order_id INT, product_id INT, PRIMARY KEY (order_id, product_id)); A close relative is FOREIGN KEY, which ensures referential integrity: values in this column must exist in the referenced parent table. A close relative is UNIQUE, which ensures all values in a column (or combination) are unique across the table. Allows NULLs (multiple NULLs allowed). A close relative is NOT NULL, which ensures a column cannot contain NULL values. More about this category: Table constraints — PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, DEFAULT.