What is the recommended batch size for SqlBulkCopy?

后端 未结 5 646
自闭症患者
自闭症患者 2020-11-30 23:34

What is the recommended batch size for SqlBulkCopy? I\'m looking for a general formula I can use as a starting point for performance tuning.

5条回答
  •  遥遥无期
    2020-12-01 00:09

    This is an issue I have also spent some time looking into. I am looking to optimize importing large CSV files (16+ GB, 65+ million records, and growing) into a SQL Server 2005 database using a C# console application (.Net 2.0). As Jeremy has already pointed out, you will need to do some fine-tuning for your particular circumstances, but I would recommend you have an initial batch size of 500, and test values both above and below this.

    I got the recommendation to test values between 100 and 1000 for batch size from this MSDN forum post, and was skeptical. But when I tested for batch sizes between 100 and 10,000, I found that 500 was the optimal value for my application. The 500 value for SqlBulkCopy.BatchSize is also recommended here.

    To further optimize your SqlBulkCopy operation, check out this MSDN advice; I find that using SqlBulkCopyOptions.TableLock helps to reduce loading time.

提交回复
热议问题