日期:2014-05-18 浏览次数:20468 次
declare mycursor cursor for select [name] from t1 open mycursor select id=row_number()over(order by [name]),* into #tmp from t2--t2要修改的表 declare @name money,@i int set @i=1 fetch next from mycursor into @name while @@fetch_status=0 begin update #tmp set [name]=@name where id=@i fetch next from mycursor into @name set @i=@i+1 end delete from t2--删掉现有数据 alter table #tmp drop column id--去掉临时表中的rownumber列 insert into goal select * from #tmp--插入新数据 drop table #tmp close mycursor deallocate mycursor ---------------------------------------