How to Specify an Input SQL File with Bcp

Can I specify an input sql file with bcp?

As far as I'm concerned the BCP utility only supports Transact-SQL queries directly written to the command line. Ex:

bcp "SELECT Name FROM AdventureWorks.Sales.Currency" queryout Currency.Name.dat -T -c

According to its reference the "-i" option:

Specifies the name of a response file, containing the responses to the command prompt questions for each data field when a bulk copy is being performed using interactive mode (-n, -c, -w, or -N not specified).

Notice that it differs from the sqlcmd Utility "-i" option:

Identifies the file that contains a batch of SQL statements or stored procedures. Multiple files may be specified that will be read and processed in order (...)

How to run a .sql file using bcp in SQL Server

use -s "|" with sqlcmd. That should allow you to out-put the data with fields separated by a tab.

-s is for column separator.

See sqlcmd Utility

Is there any way we can resume file load from nth line in a bcp utility instead of loading the file from the beginning?

Yes. BCP has a -F parameter that will let you specify a 1-based offset. So, if you wanted to skip the first 1000 rows, you'd do:

bcp yourdb.dbo.yourtable in yourfile.bcp -F 1001 ...


Related Topics



Leave a reply



Submit