Prova questo: SET @var:=0; UPDATE `table` SET `id`=(@var:=@var+1); ALTER TABLE `table` AUTO_INCREMENT=1;