【mysql】id主键列乱了之后,重新排序(可根据日期顺序)
一、ID中断不连续的,重新设置为连续的ID
alter table table_name drop id;
alter table table_name add id int not null first;
alter table table_name modify column id int not null auto_increment, add primary key(id);
select * from table_name order by id;
二、根据日期顺序,重新排列ID
alter table table_name drop id;
alter table table_name add id int not null first;
SET @row_number = 0;
UPDATE table_name
SET id = (@row_number := @row_number + 1)
ORDER BY ref_date;
alter table table_name modify column id int not null auto_increment, add primary key(id);
select * from table_name order by id;
参考文章:
mysql根据时间对数据重新更改序号_mob649e81593bda的技术博客_51CTO博客
mysql--id主键列乱了之后,重新排序_mysql 主键排序异常-CSDN博客