11. Types of primary keys: Compound
There are two types of primary keys:
- Simple
- Compound or composite
Compound or composite primary key
DEFINITION:
A compound / composite primary key combines more than one field to make a unique value.
Example 1
Sometimes, a single field is not enough to uniquely identify a record.
Consider a pack of cards. There are four suits, hearts, diamonds, clubs and spades. A single primary key would not uniquely identify a particular card based just upon the suit.
There are also thirteen values from the Ace right through to the King. Again, this would not be sufficient to uniquely identify a card.
But, if you made a primary key out of the suit and the value, then every card in the pack could be uniquely identified.
challenge see if you can find out one extra fact on this topic that we haven't already told you
Click on this link: Compound Primary Key
Example 2
A student can only be in one place at a time.
Combining the student name, date and period gives a unique value for each record.
The three fields: student, date and period make up the compound or composite primary key in this table.