我有一个超过17000行的mysql表.我从中间部分删除了大约530行.现在每行都有一个连续的AUTO-INCREAMENTED数字主键.您现在可以理解,已删除了几行数.所以我只是想问一下,有什么方法可以在一些完美的顺序中再次修复所有行?
最佳答案
您可以使用此主键作为外键,小心其他表
原文链接:https://www.f2er.com/mysql/434224.htmlSET @count = 0;
UPDATE table SET table.id = @count:= @count + 1;
这将更新表表的id列…然后你需要重置auto_increment:
ALTER TABLE table AUTO_INCREMENT = 1;
这会将下一个id从docs重置为MAX(id)1:
To change the value of the AUTO_INCREMENT counter to be used for new
rows,do this:06002
You cannot reset the counter to a value less than or equal to any that
have already been used. For MyISAM,if the value is less than or equal
to the maximum value currently in the AUTO_INCREMENT column,the value
is reset to the current maximum plus one