Understanding Composite Keys in MySQL
A composite key is a primary key or unique key made up of two or more columns. Together, these columns uniquely identify each row, even if no single column can uniquely identify the row by itself.
When a single column is not enough to uniquely identify a record.
To prevent duplicate combinations of related values.
Common in many-to-many relationship tables (junction tables).
Useful for enforcing natural relationships instead of artificial IDs.
All columns in the composite key together must be unique.
None of the composite key columns can contain NULL values.
MySQL treats the combination of values as the primary identifier of the row.
In both examples, no single column uniquely identifies a row, but the combination of the two columns does. This is the core idea of a composite key.