Search notes:

SQL Server tool: bcp

bcp is the bulk copy utility. It is used to copy data between an SQL Server instance and a data file.

Command line usage

bcp {dbtable | query} {in | out | queryout | format} datafile [options]
in Imports the content of a data file into a table or view
out Exports the content of a table or view into a data file
queryout Export the data selected by a select statement. (For example something like bcp "select * from tq84_tab" queryout x -T -d tq84_db -c).
format creates a format file based on the option values -n, -c, -w or -N. See also the -f option.

Options

-m maxerrors
-f format file Compare with -x
-e errfile
-F firstrow
-L lastrow
-b batchsize
-n native type
-c character type (TODO: Warning: -c overrides -f.)
-w wide character type
-N keep non-text native
-V file format version
-q quoted identifier
-C code page specifier
-t field terminator
-r row terminator
-i inputfile
-o outfile
-a packetsize
-S server name
-U username
-P password
-T trusted connection
-v version
-R regional enable
-k keep null values
-E keep identity values
-h "load hints"
-x generate XML format file Compare with -f
-d database name
-K application intent
-l login timeout
C:\> bcp
usage: bcp {dbtable | query} {in | out | queryout | format} datafile

Error message: Copy direction must be either 'in', 'out' or 'format'.

The command line options must be specified last when executing bcp.exe, otherwise, bcp will throw a Copy direction must be either 'in', 'out' or 'format'. error message, as for example with the following command line (because -d comes too early):
P:\ath\to\dir> bcp -d %DBNAME% "select * from xyz" queryout data.exe -c -T
Correct is:
P:\ath\to\dir> bcp "select * from xyz" queryout data.exe -c -T -d %DBNAME%

See also

Example: export and import data with bcp
The .NET class System.Data.SqlClient.SqlBulkCopy.
SQL Server tools
SQL Server: Import / export
Format files

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199813, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL-Server/tools-utilities/bcp/index(114): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78