Bulk Import and Export of Data (SQL Server)


SQL Server supports exporting data in bulk (bulk data) from a SQL Server table and importing bulk data into a SQL Server table or nonpartitioned view. Bulk importing and bulk exporting are essential to efficient transfer data between SQL Server and heterogeneous data sources. Bulk exporting refers to copying data from a SQL Server table to a data file. Bulk importing refers to loading data from a data file into a SQL Server table. For example, you can export data from a Microsoft Excel application to a data file and then bulk import that data into a SQL Server table.

In this Topic:

This section lists and briefly compares the various methods that are available for bulk importing and exporting data. The section also introduces format files.

In This Topic:

Methods for Bulk Importing and Exporting Data

SQL Server supports bulk exporting data from a SQL Server table and for bulk importing data into a SQL Server table or nonpartitioned view. The following basic methods are available.

MethodDescriptionImports dataExports data
bcp utilityA command-line utility (Bcp.exe) that bulk exports and bulk imports data and generates format files.YesYes
BULK INSERT statementA Transact-SQL statement that imports data directly from a data file into a database table or nonpartitioned view.YesNo
INSERT ... SELECT * FROM OPENROWSET(BULK...) statementA Transact-SQL statement that uses the OPENROWSET bulk rowset provider to bulk import data into a SQL Server table by specifying the OPENROWSET(BULK…) function to select data in an INSERT statement.YesNo
System_CAPS_ICON_important.jpg Important

Comma-separated value (CSV) files are not supported by SQL Server bulk-import operations. However, in some cases, a CSV file can be used as the data file for a bulk import of data into SQL Server. Note that the field terminator of a CSV file does not have to be a comma. For more information, see Prepare Data for Bulk Export or Import (SQL Server).

Format Files

The bcp utility, BULK INSERT, and INSERT ... SELECT * FROM OPENROWSET(BULK...) all support the use of a specialized format file that stores format information for each field in a data file. A format file might also contain information about the corresponding SQL Server table. The format file can be used to provide all the format information that is required to bulk export data from and bulk import data to an instance of SQL Server.

Format files provide a flexible way to interpret data as it is in the data file during import, and also to format data in the data file during export. This flexibility eliminates the need to write special-purpose code to interpret the data or reformat the data to the specific requirements of SQL Server or the external application. For example, if you are bulk exporting data to be loaded into an application that requires comma-separated values, you can use a format file to insert commas as field terminators in the exported data.

SQL Server supports two kinds of format files: XML format files and non-XML format files.

The bcp utility is the only tool that can generate a format file. For more information, see Create a Format File (SQL Server). For more information about format files, see Format Files for Importing or Exporting Data (SQL Server).

System_CAPS_ICON_note.jpg Note

In cases when a format file is not supplied during a bulk export or import operations, you can override the default formatting at the command line.

To use a format file

To use data formats for bulk import or bulk export

To specify data formats for compatibility when using bcp

  1. Specify Field and Row Terminators (SQL Server)

  2. Specify Prefix Length in Data Files by Using bcp (SQL Server)

  3. Specify File Storage Type by Using bcp (SQL Server)

Prerequisites for Minimal Logging in Bulk Import
Format Files for Importing or Exporting Data (SQL Server)
Examples of Bulk Import and Export of XML Documents (SQL Server)
SQL Server Integration Services
Copy Databases to Other Servers
Performing Bulk Load of XML Data (SQLXML 4.0)
Performing Bulk Copy Operations
bcp Utility
Format Files for Importing or Exporting Data (SQL Server)