List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 18 2003 3:04am
Subject:Re: converting an existing column to auto increment
View as plain text  
At 18:08 -0600 3/17/03, Liz Buckley-Geer wrote:
>I have an table with a column
>
>number        INT NOT NULL PRIMARY KEY
>
>This table contains many records and there are gaps in the number 
>sequence. I would like to modify this column to use the AUTO 
>INCREMENT feature but I need to preserve the present numbering 
>sequence (which is monotonically increasing) including the holes. It 
>is not clear from the manual or my MySQL book exactly how to do this.
>
>Is this possible? if so what is the correct ALTER TABLE command?

Interesting question.

My tests suggest that, yes, you can do this.  But make sure you backup
the table first.

The statement I used was

ALTER TABLE tbl_name MODIFY number INT NOT NULL AUTO_INCREMENT;

>
>        Thanks Liz


-- 
Paul DuBois
http://www.kitebird.com/
sql, query
Thread
converting an existing column to auto incrementLiz Buckley-Geer18 Mar
  • Re: converting an existing column to auto incrementBenjamin Pflugmann18 Mar
  • Re: converting an existing column to auto incrementPaul DuBois18 Mar
    • Re: converting an existing column to auto incrementLiz Buckley-Geer18 Mar