首页 > 解决方案 > 如何使用以下查询进行批量更新

问题描述

Merge DBO1..tblinventoryStock_Targer as T

Using   DBO2..tblinventoryStock_Source as S

on S.Inventorycode =T.Inventorycode  and 

S.Locationcode =T.Locationcode

when matched then 
update set T.QtyOnhand  = S.QtyonHand,
T.Modifydate=S.Modifydate,
T.QtySold = S.QtySold  

when not matched by Target then
insert  ( --Fields)
values(--Values);

我必须将它从 DB2 插入到 sql server 中的 DB1 我有大约一百万条记录。如何快速进行更新和插入我需要 5 分钟通过 C# 使用存储过程执行查询

标签: sql-servermergebulkupdate

解决方案


当您执行可能会影响一百万行的 UPDATE 时,最好分批执行。一次尝试 50,000 行的批次。


推荐阅读