After mysql delete ID discontinuous solutions

Methods 10 million, a sufficient grasp, here two weeks method, which likes to use which:

1, delete increment field, and then rebuild (the disadvantage is the need to keep in mind from other properties by field, or may lead to some unknown problem)

复制代码
1.ALTER TABLE `tablename` DROP COLUMN `id`;
2.ALTER TABLE `tablename` ADD `id` int(10) unsigned NOT NULL AUTO_INCREMENT FIRST,ADD PRIMARY KEY (`id`), AUTO_INCREMENT = 0 ROW_FORMAT = COMPACT;

Method 2, by the self-energizing reset sql statement field values ​​in order to achieve the method:

复制代码
1.SET @i=0;
2.UPDATE `tablename` SET `id`=(@i:=@i+1);
3.ALTER TABLE `tablename` AUTO_INCREMENT=0;

 

Guess you like

Origin www.cnblogs.com/liangliangzz/p/11095215.html