批量插入记录到SQL Server数据库 [英] Bulk insert records into SQL Server database
问题描述
我有一个包含约一百万条记录的文本文件。是什么将它们插入到从C#?
I have a text file that contains about a million records. What is the best way to insert them into a SQL Server database from C#?
我可以使用 BULK INSERT
?
推荐答案
最好的办法是使用 BCP
实用或 SSIS的工作流一>。这些工具有像缓存改进和配料你会在一个天真的实施错过。接下来最好的选择是 BULK INSERT
声明只要SQL Server引擎本身可达到该文件。最后的选择将是<一href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx"><$c$c>SqlBulkCopy$c$c>级,从而使您的应用程序做阅读文件,可能处理它,改造它,然后喂数据作为枚举器使用SqlBulkCopy。
Best way is to use the bcp
utility or an SSIS workflow. Those tools have refinements like caching and batching your will miss in a naive implementation. Next best option is BULK INSERT
statement, as long as the SQL Server engine itself can reach the file. Last option would be SqlBulkCopy
class which allows your app do read the file, maybe process it and transform it, then feed the data as an enumerator to the SqlBulkCopy.
这篇关于批量插入记录到SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!