【发布时间】:2023-04-05 23:20:01
【问题描述】:
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 我有大约一百万条记录。如何快速进行更新和插入,使用存储过程通过 C# 执行查询需要 5 分钟
【问题讨论】:
-
那么您有一个可以完成这项工作的 c# 函数吗?请张贴。这显示了你到目前为止所尝试的。提供一些伪代码并期望获得可运行的解决方案并不是 stackoverflow 的本意。因为你是新来的,这是一个很好的阅读:stackoverflow.com/help/how-to-ask
-
尝试使用一些列如修改日期的增量数据更新策略。仅将新更新的记录与目标合并,而不扫描整个表。并在运行查询时验证是否使用了正确的索引。
标签: sql-server merge bulkupdate