首先设置一个变量,初始值为0:code
set @r:=0;
而后更新表中对应的ID列:it
update tablename set id=(@r:=@r+1)
若是是插入,那就找一个记录多的表t1table
set @r:=0; insert into t select @r:=@r+1 from t1 limit 0, 2000
@完变量