A composite key consists of two or more columns that together uniquely identify a record or relationship.
Some database designs require multiple columns to uniquely identify a business record.
Use ProductID and StoreID together to identify inventory for a specific product at a specific store.
SELECT
i.ProductID,
i.StoreID,
i.Quantity,
p.ProductName
FROM Inventory i
INNER JOIN Products p
ON i.ProductID = p.ProductID;
Composite keys are common in inventory, banking, regional reporting, mapping tables, and transaction systems.
- A composite key uses multiple columns.
- Columns together can identify a unique relationship.
- JOIN conditions may use all key columns.
- Composite keys are common in bridge and transaction tables.
- Correct key design prevents incorrect matches.
What is a composite key?
A composite key is a key made up of two or more columns that together identify a record.
Why are composite keys useful?
They are useful when no single column can uniquely identify a business record or relationship.