alter table aa add temp_id int identity(int,1,1)
goselect temp_id=identity(int,1,1),id into #t from a
update aa set id=b.id
from aa join #t b on aa.temp_id=b.temp_idinsert aa(id)
select id from #t a
where not exists(select 1 from aa where temp_id=a.temp_id)
godrop table #t
goalter table aa drop column temp_id
goselect temp_id=identity(int,1,1),id into #t from a
update aa set id=b.id
from aa join #t b on aa.temp_id=b.temp_idinsert aa(id)
select id from #t a
where not exists(select 1 from aa where temp_id=a.temp_id)
godrop table #t
goalter table aa drop column temp_id
goselect temp_id=identity(int,1,1),id into #t from a
update aa set id=b.id
from aa join #t b on aa.temp_id=b.temp_idinsert aa(id)
select id from #t a
where not exists(select 1 from aa where temp_id=a.temp_id)
godrop table #t
goalter table aa drop column temp_id
答案好像是错的. 下面语句的标志列不是按顺序排列的.
alter table aa add temp_id int identity(1,1)