Sometimes more than one attribute needs to create a key that uniquely represents a tuple. That keys are known as a composite key or compound key.
Any>super key,>primary key,>candidate key>can be called a composite key if it has more than one attribute.
Lets consider a table Sales with four attributes or columns – customer_id, order_id, pcode and qty.
customer_id | order_id | pcode | Qty |
---|---|---|---|
C001 | O922 | P006 | 20 |
C002 | O889 | P007 | 5 |
C003 | O876 | P005 | 34 |
C003 | O777 | P006 | 66 |
Here, none of these columns can declare as a primary key that uniquely identifies a tuple. Because
Here only the combination of customer_id and order_id can uniquely identify a tuple and can be declared as the primary key. That is why the said set of keys known as a composite key.