List:General Discussion« Previous MessageNext Message »
From:Martijn Tonies Date:December 26 2006 3:51pm
Subject:Re: Primary field do I need one
View as plain text  

> I'm working through (my first day) PHP & MySQL for Dummies and I'm stuck
> the primary field for my database.
> I want to create a racing pigeon results database that has 6 fields only.
> The results will be imported into the database in bulk from a CSV file
> Owner - GBring - Ering - Arrivedtime - date - position
> If I'm not wrong, surely whichever one of the first 3 fields I create as a
> primary field will stop me entering any races after the first one, because
> every race thereafter will always for the most part be the same owners and
> rings.
> So do I have to have a primary key?

Of course.

Let me explain:

There are 2 types of primary keys. In theory, you should use a primary
key that is derived from your data. That is, for example, if you were
info about books, the ISBN number, if it was unique, could be your primary

The other type of PK is an auto-increment (or whatever) generated ID

Without a primary (or unique) key, you have no way of identifying a specific
row in your table. Which means you cannot delete or modify specific rows.

Now, you can have a "compound primary key", which consists of multiple
columns or a single column primary key.

When is a primary key useful? In your example, it could help to avoid
entering the info about the same pigeon multiple times for each race.
This would require a compound primary key, eg:

RaceID (some unique number or startingdate or so) and PigeonID
(some unique thingy on the pigeons ring?)

This would allow you to enter multiple races per pigeon, and still
get to identify a single row uniquely, wouldn't it?

Have a merry X-mas.

Martijn Tonies
Database Workbench - development tool for MySQL, and more!
Upscene Productions
My thoughts:
Database development questions? Check the forum!

Primary field do I need onemeridklt26 Dec
  • Re: Primary field do I need oneMartijn Tonies26 Dec
  • Re: Primary field do I need onemeridklt26 Dec
  • RE: Primary field do I need oneJerry Schwartz27 Dec
RE: Primary field do I need oneJay Blanchard26 Dec