Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add auto increment to existing column

Status
Not open for further replies.

Foamcow

Programmer
Nov 14, 2002
6,092
GB
Hi,

This is probably dead simple but I'm stuck!

I have a table with 126 rows in it. The guy that originally created the table didn't think to make the id column an auto incremented one.

For the PHP script I am writing I could really do with making the id column auto increment.

I've tried

Code:
ALTER TABLE products CHANGE product_id product_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT

But that throws a duplicate entry error.
Basically I want to convert product_id column to auto increment starting from 127 and keep the first 126 in there with the id numbers they already have.



<honk>*:O)</honk>
Foamcow Heavy Industries - Web site design in Cheltenham and Gloucester
Ham and Jam - British & Commonwealth forces mod for Half Life 2
 
It isn't a bug. you can't have a value of less than 1 in an auto increment column.
 
Yeah, that makes sense. Thanks.

When I researched it I found a bug report on the MySQL site.
It refered to values of 0 and 1, I removed the 2 rows that had those id's and it then let me make the column an auto increment one.
I've not tested beyond that so it may or may not be true!




<honk>*:O)</honk>
Foamcow Heavy Industries - Web site design in Cheltenham and Gloucester
Ham and Jam - British & Commonwealth forces mod for Half Life 2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top