A primary key (PK) is a unique index on a table.
Every table should have one.
If you have multiple tables, each one should have its own PK.
A database sorts its records in the way you specify in your query. So if a
table has 2 identical rows, and you ask to update one of them, which one
gets changed? The answer is not properly defined. Therefore every table
should have some way to uniquely identify each record. That's what the PK
does.
A simple way to add a PK to a table is to add an AutoNumber field. Since the
number is different on every row, it uniquely identifies which row you are
talking about, so it can be the PK.
In other tables, there may be an obvious natural key field without needing
to add an autonumber. For example, if you have a table of categories, the
category name will be unique, so you can use it as the PK.
You can use a combination of several fields together as the PK. For example,
if you sell limited edition prints of your photos, then the PhotoID field
plus the EditionNumber field would make a good PK.
Some examples that do NOT make good primary key fields:
- people's names: different people can have the same name.
- SSN: problems with identity theft, and people from other countries.