Database primary keys

It is vital for the DBMS that every record can be uniquely identified.

In the example from the previous page each person could be uniquely identified by their first name. What if there were two Sara's? You could use a combination of first name and surname but again there could be two Sara Jones. Often a table will include a field which must be unique to each record. This is known as a primary key. It is used to identify which record is being used:

personID firstname surname dob
1 John Smith 01/12/76
2 Sara Jones 13/06/69
3 Sara Jones 1/04/68
4 Fred Bloggs 11/11/73

Primary keys are often numbers but can be anything as long as every one is different. If they are numbers they are often set automatically so that no mistakes can be made (the user might put the same number for two records). This is known as auto-increment.

submit to reddit Delicious Tweet