Primary Key
A primary key is needed to provide a unique way to identify one record (row) from another within a database table.
Fields marked as a primary key will not allow duplicate entries in that field (table column).
Without primary keys, we could easily get people/objects mixed up in a database, e.g. imagine failing a GCSE because your exam score was mixed up with that of another student with the same name.
Choosing a primary key
Typically, when designing your database, you would first look at your existing choice of fields to see if any are suitable to act as the primary key.
No matter how unlikely it may be, any chance of a duplication of data within that field would make it unsuitable to be the primary key.
This rules out post codes, date of births and names etc as someone else could also share this information, making it impossible to tell those two people apart in the database.
If no fields are found to be suitable, then a new field must be created with the sole purpose to uniquely identify records from one another. This could be an account number, id number etc.
Real life examples
- Vehicle registration plates
- Passport number
- Bank account sort code and account number
- Student ID number
- Utility bill account number
- School exam centre number