> 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
> So do I have to have a primary key?
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.
Database Workbench - development tool for MySQL, and more!
Database development questions? Check the forum!