Reorder / reset auto increment primary key

后端 未结 15 1604
北荒
北荒 2020-11-22 04:39

I have a MySQL table with an auto increment primary key. I deleted some rows in the middle of the table. Now I have, for example, something like this in the ID column: 12, 1

15条回答
  •  花落未央
    2020-11-22 05:06

    This works - https://stackoverflow.com/a/5437720/10219008.....but if you run into an issue 'Error Code: 1265. Data truncated for column 'id' at row 1'...Then run the following. Adding ignore on the update query.

    SET @count = 0;
    set sql_mode = 'STRICT_ALL_TABLES';
    UPDATE IGNORE web_keyword SET id = @count := (@count+1);
    

提交回复
热议问题