简体   繁体   English

更新SQL Server中的大量记录-性能不佳

[英]Update a large number of records in SQL Server - poor performance

I have a simple query to update a very large number of records ~20 million. 我有一个简单的查询,可以更新大约2000万条记录。 The update is done on a remote server from where the original update statement runs and there are several joins in the query. 更新是在运行原始更新语句的远程服务器上完成的,查询中有多个联接。

Wanted to see if anybody has any tips on making this query run a bit faster. 想看看是否有人对使此查询运行更快有任何提示。 it's currently running for hours. 它已经运行了几个小时。

I thought about getting a list of unique id's from a select statement and then run the update on the remote server but I'm sure there are better ways to get this done. 我考虑过从select语句中获取唯一ID的列表,然后在远程服务器上运行更新,但是我敢肯定,有更好的方法可以完成此操作。

Thanks. 谢谢。

Do it by batches or use bulkcopy. 分批执行或使用批量复制。

Here is an example on bulkcopy and update 这是有关批量复制和更新的示例

http://www.aspsnippets.com/Articles/SqlBulkCopy--Bulk-Insert-records-and-Update-existing-rows-if-record-exists-using-C-and-VBNet.aspx http://www.aspsnippets.com/Articles/SqlBulkCopy--批量插入-记录-和更新-existing-rows-if-record-exists-使用-C-和-VBNet.aspx

A proper index cannot hurt. 适当的索引不会造成伤害。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM