Reorder / reset auto increment primary key

后端 未结 15 1715
北荒
北荒 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:12

    You could drop the primary key column and re-create it. All the ids should then be reassigned in order.

    However this is probably a bad idea in most situations. If you have other tables that have foreign keys to this table then it will definitely not work.

提交回复
热议问题