1.批量处理的方法,大大节约系统资源并提高效率。
update Table1
set Table1.co1 = Table2.co1,
Table1.co2 = Table2.co2
from Table2
where Table2.id = Table1.id
2.实在不得不逐条遍历的话,有两种方法:
1)利用游标
declare @co1 int,@co2 int
--申明游标
declare my_cursor cursor for
select top 10 A.co1,B.co2
from Table1 A inner join Table2 B
on A.co2 = B.co2
--打开游标
open my_cursor
fetch next from my_cursor into @co1,@co2
--循环游标
while @@fetch_status = 0