Or you don't have to at all.
MySQL has a built in auto increment feature.
This snippet was taken from a PHPMyAdmin table creation
- CREATE TABLE `test` (
-
`id` INT( 3 ) NOT NULL AUTO_INCREMENT ,
-
PRIMARY KEY ( `id` ) ,
-
UNIQUE (`id`)
-
)
This, from a table update
- ALTER TABLE `testing` ADD UNIQUE (`id`)
-
// Then ...
-
ALTER TABLE `testing` CHANGE `id` `id` INT( 5 ) NOT NULL AUTO_INCREMENT
Its important the tables column is set to unique, as it is required for the auto feature. Also note, only one auto feature is allowed per table. You can more then one unique index, though you'd have to be careful of that you enter into that column.
Every insert you make into that table with increment the ID value from my example. Just a side note, deleting table entrys doesn't effect the increment value.