can i alter a table column to make it auto increment?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
crimius
Forum Commoner
Posts: 28
Joined: Sun Oct 13, 2002 6:02 pm
Location: Austin, Texas
Contact:

can i alter a table column to make it auto increment?

Post by crimius »

the column in question is the primary key.

there are already records in the table.

thanks :)
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

My guess would be no, but that's just a guess. auto_incrementing fields can't have duplicates as you know, but when the engine is told to change a field to auto_increment, does it check to see if dups exist? If it does and there are, I'm sure it would choke. And it should (!) or else your talking about a potential corruption of data. :evil:

Check the manual for your db and try to find out. :wink:

Cheers,
BDKR
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

Shouldn't be any problem at all if the column is Unique (Which it is if it is a primary key and not composed) and of some Integer type... Take a backup of your data before trying anyway to be safe..
crimius
Forum Commoner
Posts: 28
Joined: Sun Oct 13, 2002 6:02 pm
Location: Austin, Texas
Contact:

another question

Post by crimius »

Yah, all the entries for that column are unique.

I'm using MySQL...does anyone know the ALTER command for making that column auto increment?

Thanks for the info!
Caroline
Forum Commoner
Posts: 25
Joined: Thu Jan 30, 2003 1:38 pm

Try this

Post by Caroline »

I don't say it will work, but it may work

Use phpMyAdmin, browse to your table, click on change in the column field and make

Extra >>> Auto increment

Hope that work[/url]
Post Reply