Connecting with bcp
The bcp utility is available in the Microsoft ODBC Driver for SQL Server on Linux and macOS. This page documents the differences from the Windows version of
The field terminator is a tab ("\t").
The line terminator is a newline ("\n").
Character mode is the preferred format for
bcpformat files and data files that do not contain extended characters.
A backslash '\' on a command-line argument must either be quoted or escaped. For example, to specify a newline as a custom row terminator, you must use one of the following mechanisms:
The following is a sample command invocation of
bcp to copy table rows to a text file:
bcp AdventureWorks2008R2.Person.Address out test.dat -Usa -Pxxxx -Sxxx.xxx.xxx.xxx
In the current release, the following syntax and options are available:
[database.]schema.table in data_file | out data_file
Specifies the number of bytes, per network packet, sent to and from the server.
Specifies the number of rows per batch of imported data.
Uses a character data type.
Specifies the database to connect to.
Causes the value passed to the
bcp-S option to be interpreted as a data source name (DSN). For more information, see "DSN Support in sqlcmd and bcp" in Connecting with sqlcmd.
-e error_file Specifies the full path of an error file used to store any rows that the
bcputility cannot transfer from the file to the database.
Uses an identity value or values in the imported data file for the identity column.
Specifies the full path of a format file.
Specifies the number of the first row to export from a table or import from a data file.
Specifies that empty columns should retain a null value during the operation, rather than have any default values for the columns inserted.
Specifies a login timeout. The –l option specifies the number of seconds before a login to SQL Server times out when you try to connect to a server. The default login timeout is 15 seconds. The login timeout must be a number between 0 and 65534. If the value supplied is not numeric or does not fall into that range,
bcpgenerates an error message. A value of 0 specifies an infinite timeout.
Specifies the number of the last row to export from a table or import from a data file.
Specifies the maximum number of syntax errors that can occur before the
bcpoperation is cancelled.
Uses the native (database) data types of the data to perform the bulk-copy operation.
Specifies the password for the login ID.
Executes the SET QUOTED_IDENTIFIERS ON statement in the connection between the
bcputility and an instance of SQL Server.
Specifies the row terminator.
Specifies that currency, date, and time data is bulk copied into SQL Server using the regional format defined for the locale setting of the client computer.
Specifies the name of the SQL Server instance to connect to, or if -D is used, a DSN.
Specifies the field terminator.
Specifies that the
bcputility connect to SQL Server with a trusted connection (integrated security).
Specifies the login ID used to connect to SQL Server.
bcputility version number and copyright.
Uses Unicode characters to perform the bulk copy operation.
In this release, Latin-1 and UTF-16 characters are supported.
In the current release, the following syntax and options are not available:
Specifies the code page of the data in the data file.
Specifies the hint or hints used during a bulk import of data into a table or view.
Specifies the name of a response file.
Uses the native (database) data types of the data for noncharacter data, and Unicode characters for character data.
Specifies the name of a file that receives output redirected from the command prompt.
-V (80 | 90 | 100)
Uses data types from an earlier version of SQL Server.
Used with the format and -f format_file options, generates an XML-based format file instead of the default non-XML format file.