为了做演示数据,本来人员表里有好几千条数据,但姓名那一列都测试时录入的“ABC”,"A1"这些测试信息
我在网上找了一个真实的人名单,我已经把他导到一个临时表中了,我想把现有人员表的“姓名”字段更新为临时表里的“人名”
------解决方案--------------------
- SQL code
declare mycursor cursorforselect [name] from t1open mycursorselect id=row_number()over(order by [name]),* into #tmp from t2--t2要修改的表 declare @name money,@i intset @i=1fetch next from mycursor into @namewhile @@fetch_status=0begin update #tmp set [name][email protected] where [email protected] fetch next from mycursor into @name set @[email protected]+1 enddelete from t2--删掉现有数据alter table #tmp drop column id--去掉临时表中的rownumber列insert into goal select * from #tmp--插入新数据drop table #tmpclose mycursordeallocate mycursor---------------------------------------