DROP PROCEDURE IF EXISTS `CreateIndex` $$
CREATE PROCEDURE `CreateIndex`()
BEGIN
SET @rn=0;
UPDATE `表名` SET id = (@rn:=@rn+1) ORDER BY '列名' ASC;
alter table `表名`add PRIMARY KEY (id);
ALTER TABLE `表名` MODIFY id int(10) unsigned NOT NULL auto_increment;
END $$