如何SqlBulkCopy的工作 [英] How does SqlBulkCopy Work
问题描述
我熟悉C#SqlBulkCopy类,您可以拨打在WriteToServer方法通过一个DataTable。
I am familiar with the C# SqlBulkCopy class where you can call the 'WriteToServer' method passing through a DataTable.
我的问题是在SQL服务器的底层机制用于批量插入数据?
My question is what underlying mechanism in SQL server is used to bulk insert that data?
我想问的原因是,批量插入在批量插入一> MSDN T-SQL的帮助文件需要导入数据文件。是否SqlBulkCopy的创建数据文件?
The reason I ask is that the bulk insert referenced in the Bulk Insert MSDN T-SQL help file requires a data file to import. Does the SqlBulkCopy create a data file?
我想明白这东西摸出我是否可以使用批量插入功能的SQL。
I would like to understand this stuff to work out whether I can use the bulk insert functionality in SQL.
如果我写的prepares所有行插入到特定的表(几千行)我可以大量把它们插入到目标表中的SQL语句?这样的事情是,我怎么做,现在,
If I write a SQL statement that prepares all the rows to insert into a particular table (thousands of rows) can I bulk insert them into the destination table? Something like this is how I am doing it now,
INSERT INTO sync_filters (table_name, device_id, road_id, contract_id)
SELECT * FROM dbo.sync_contract_filters (@device_id)
而dbo.sync_contract_filters功能可生成所有插入行。可这是批量插入?
And the dbo.sync_contract_filters is a function to generate all the rows to insert. Can this be bulk inserted?
推荐答案
SqlBulkCopy的不创建一个数据文件。它直接从净DataTable对象到服务器使用由BCP相同的技术使用可用的通信协议(命名管道,TCP / IP等...)和插入数据到目标表批量流中的数据表
SqlBulkCopy does not create a data file. It streams the data table directly from the .Net DataTable object to the server using the available communication protocol (Named Pipes, TCP/IP, etc...) and insert the data to the destination table in bulk using the same technique used by BCP.
这篇关于如何SqlBulkCopy的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!