>
> I'm working through (my first day) PHP & MySQL for Dummies and I'm stuck
on
> 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
storing
info about books, the ISBN number, if it was unique, could be your primary
key.

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

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
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to