设计表table1中一列ID递增,但在插入数据过程中出现数据排列不规范,将ID更新为递增,方法如下:
1、取消列ID的主键和递增标识
2、把数据提取到临时表
select identity(int,1,1) as tid, ID into #临时表名 from 原表名 order by ID
select * from #临时表名 order by ID
3、更新目标表原表名的列ID
update 原表名 set ID = tid from #临时表名 where #ttttt.ID =原表名.ID
select * from 原表名 order by ID
4、删除中间表
drop table #临时表名
SQL更新一列为递增数字的处理方法
最新推荐文章于 2024-01-22 21:56:48 发布