简体   繁体   English

SQLBulkCopy或批量插入

[英]SQLBulkCopy or Bulk Insert

I have about 6500 files for a sum of about 17 GB of data, and this is the first time that I've had to move what I would call a large amount of data. 我有大约6500个文件,总和大约17 GB的数据,这是我第一次不得不移动我称之为大量数据的东西。 The data is on a network drive, but the individual files are relatively small (max 7 MB). 数据位于网络驱动器上,但各个文件相对较小(最大7 MB)。

I'm writing a program in C#, and I was wondering if I would notice a significant difference in performance if I used BULK INSERT instead of SQLBulkCopy. 我正在用C#编写程序,如果我使用BULK INSERT而不是SQLBulkCopy,我想知道是否会注意到性能的显着差异。 The table on the server also has an extra column, so if I use BULK INSERT I'll have to use a format file and then run an UPDATE for each row. 服务器上的表也有一个额外的列,所以如果我使用BULK INSERT,我将不得不使用格式文件,然后为每一行运行UPDATE。

I'm new to forums, so if there was a better way to ask this question feel free to mention that as well. 我是新来的论坛,所以如果有更好的方式来问这个问题,请随意提及。

By test, BULK INSERT is much faster. 通过测试,BULK INSERT 快得多。 After an hour using SQLBulkCopy, I was maybe a quarter of the way through my data, and I had finished writing the alternative method (and having lunch). 使用SQLBulkCopy一小时后,我可能只有四分之一通过我的数据,我已经完成了替代方法的编写(和午餐)。 By the time I finished writing this post (~3 minutes), BULK INSERT was about a third of the way through. 当我写完这篇文章(约3分钟)时,BULK INSERT大约有三分之一的时间。

For anyone who is looking at this as a reference, it is also worth mentioning that the upload is faster without a primary key. 对于那些将此视为参考的人来说,值得一提的是,如果没有主键,上传速度会更快。

It should be noted that one of the major causes for this could be that the server was a significantly more powerful computer, and that this is not an analysis of the efficiency of the algorithm, however I would still recommend using BULK INSERT, as the average server is probably significantly faster than the average desktop computer. 应该注意的是,其中一个主要原因可能是服务器是一台功能更强大的计算机,并且这不是对算法效率的分析,但是我仍然建议使用BULK INSERT作为平均值。服务器可能比普通台式计算机快得多。

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

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