I need you save my live. I have a table with a LOT of rows. One of the fields are id, it have auto_increment.
For legally reasons, now I need to have another auto increment field (not auto_numeric, I will be control this manually). It fields in the firs row starts at 567.
How I can add i exists rows the new correlative number? 568 ,569, 570...
Just create a new int field and then update it with
UPDATE table SET new_column = auto_increment_column + 567;
Of course, that will also keep all the breaks in the original column. You can drop the auto_increment
field and re-add it to eliminate it. It'll take a few hours, but a life's worth it, I guess.
If you really need to manually renumber the fields, you'll probably just have to go the way the previous commenters have suggested and use either PHP or cursors to loop through all the records.
I found the solution:
SET @pos =566; UPDATE mytable SET field_id2 = ( SELECT @pos := @pos +1 ) ORDER BY id ASC;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.