Auto Increment after delete in MySQL

后端 未结 17 1780
醉酒成梦
醉酒成梦 2020-11-22 09:50

I have a MySQL table with a primary key field that has AUTO_INCREMENT on. After reading other posts on here I\'ve noticed people with the same problem and with varied answer

17条回答
  •  伪装坚强ぢ
    2020-11-22 10:43

    There is actually a way to fix that. First you delete the auto_incremented primary key column, and then you add it again, like this:

    ALTER TABLE table_name DROP column_name;
    ALTER TABLE table_name ADD column_name int not null auto_increment primary key first;
    

提交回复
热议问题