Efficient SQL UPDATE command for many rows

后端 未结 2 660
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 10:35

My problem is not one of \"Able to\", but \"able to quickly\"

I have a table with a static number of rows for which multiple items per row need to be updated frequen

相关标签:
2条回答
  • 2020-12-22 10:45

    Have your code call the System.Data.SqlClient.SqlBulkCopy API to Bulk Insert your change data into a staging table, then use an UPDATE command to read the staging data and update your target table with it.

    The reason for this approach is that all of the methods above suffer from the same basic performance bottleneck: getting the data into SQL Server in the first place. Once it's in there, there are many ways to turn that static data into an UPDATE, all with very good performance.

    0 讨论(0)
  • 2020-12-22 10:59

    If your sql server version is 2008+ then I recommend to create stored procedure and pass into this SP table valued parameter with all the data to update. This will perform much more quickly

    0 讨论(0)
提交回复
热议问题