Forum Moderators: open

Message Too Old, No Replies

Is it possible to force an auto increment re-count?

I want to re-auto_increment after sorting

         

xxclixxx

1:05 am on Jan 10, 2007 (gmt 0)

10+ Year Member


I'd like to know if it's possible to get MySQL to re-count an auto incremented index?

Basically what I'd like to do is have an auto incremented index that I dump a bunch of data into, and then sort the table data, and re-index it so the index number is in order by the table data.

Example:

Insert "Big Recipe" (given id 1)
Insert "Cats are Cool" (given id 2)
Insert "Are you paying attention" (given id 3)

ALTER TABLE `posts` ORDER BY `Title` ASC

? missing statement goes here?

Then the table would be:
"Are you paying attention" (given id 1)
"Big Recipe" (given id 2)
"Cats are Cool" (given id 3)

Thanks for the help!

LifeinAsia

1:09 am on Jan 10, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You should be able to resort the table, delete the original ID column, and add a new autocount column.

xxclixxx

1:11 am on Jan 10, 2007 (gmt 0)

10+ Year Member



Sweet I didn't think to do that, thanks it works great =P

justageek

3:12 pm on Jan 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also do this: alter table tbl_name auto_increment = 1;

JAG