ערוך

Bulk Copy Operations in SQL Server

Microsoft SQL Server includes a popular command-line utility named bcp for quickly bulk copying large files into tables or views in SQL Server databases. The SqlBulkCopy class lets you write managed code solutions that provide similar functionality. There are other ways to load data into a SQL Server table (INSERT statements, for example) but SqlBulkCopy offers a significant performance advantage over them.

The SqlBulkCopy class writes data only to SQL Server tables. The data source isn't limited to SQL Server. Use any source that loads data into the DataTable class or exposes it through the IDataReader interface.

With the SqlBulkCopy class, you can perform:

  • A single bulk copy operation

  • Multiple bulk copy operations

  • A bulk copy operation within a transaction

Note

To load data from a file accessible to the server, execute the Transact-SQL (T-SQL) BULK INSERT statement with SqlCommand. This operation reads the file on the server, unlike SqlBulkCopy, which sends data from the client.

In This Section

Bulk Copy Example Setup Describes the tables used in the bulk copy examples and provides SQL scripts for creating the tables in the AdventureWorks database.

Single Bulk Copy Operations Describes how to do a single bulk copy of data into an instance of SQL Server using the SqlBulkCopy class, and how to perform the bulk copy operation using Transact-SQL statements and the SqlCommand class.

Multiple Bulk Copy Operations Describes how to do multiple bulk copy operations of data into an instance of SQL Server using the SqlBulkCopy class.

Transaction and Bulk Copy Operations Describes how to perform a bulk copy operation within a transaction, including how to commit or rollback the transaction.

See also