Speed up update of 185k rows in SQL Server 2008?

前端 未结 3 1359
无人及你
无人及你 2020-12-19 14:17

I have a binary file with about 185k rows in it. C# parses file in seconds. What would be the best way to update MSSQL table with

3条回答
  •  粉色の甜心
    2020-12-19 14:44

    Use SqlBulkCopy (to a temporary table) followed by MERGE.

    The bulk-copy method can efficiently transfer data using a "push" from a .NET client. Using BULK INSERT requires a "pull" from the server (along with the required local-file access).

    Then the MERGE command (in SQL Server 2008+) can be used to insert/update/upsert the data from the temporary table to the target table according to the desired rules. Since the data is entirely in the database at this point, this operation will be as fast as can be. Using MERGE may also result in performance advantages over many individual commands, even those within the same transaction.

    See also:

    • Any way to SQLBulkCopy "insert or update if exists"?
    • SQL Server 2008 INSERT Optimization

提交回复
热议问题