A composite primary key is a primary key that consists of two or more columns. Together they will always provide a unique value within the table. In other words, the combination of both values will be unique across all rows – no two rows will share the same combined value.
In MySQL we can create a composite primary key with the PRIMARY KEY
clause of the CREATE TABLE
statement. We can also use the ADD PRIMARY KEY
statement to add a composite primary key to an existing table that doesn’t already have a primary key.