What is a primary key?

J

John

If someone can please explain what a primary key in access is, I would
appreciate it. Also in a database that has multiple tables, are there
multiple primary keys?

Thanks for helping. Obviously I'm a newbie.
 
A

Allen Browne

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.
 
D

David Cressey

John said:
If someone can please explain what a primary key in access is, I would
appreciate it. Also in a database that has multiple tables, are there
multiple primary keys?

Thanks for helping. Obviously I'm a newbie.

Here's a pretty good description, from an introduction to data modeling.

http://www.utexas.edu/its-archive/windows/database/datamodeling/dm/keys.html

You may have to get past a screen that says that this website is being
archived.

The description is not specific to MS ACCESS, and uses some terminology that
may be a little different than what you are used to. It's worth the effort.
 
R

RoyVidar

John said:
If someone can please explain what a primary key in access is, I would
appreciate it. Also in a database that has multiple tables, are there
multiple primary keys?

Thanks for helping. Obviously I'm a newbie.

Here is one introduction to relational databases, with a bit of
information.

http://r937.com/relational.html
 
T

Tom van Stiphout

You can think of a PK as the most important unique index on a table.
It defines what makes each row in that table unique.

Each table should have a PK.

A PK, just like any other index, can be over multiple fields.

-Tom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top