BCP Utility

BCP utility in Sql Server

BCP is an acronym for Bulk Copy Program. It is a command-line utility of Sql Server. With the help of BCP we can export data from database table to flat files, from results of database queries to flat files and we can import the data from flat files to database tables.

Syntax: bcp {[[database_name.][owner].]database table or view | “query”}{in|out|queryout|format} data_file [-r row_terminator] [-t field_terminator] [-S server_name[\instance_name]] [-U login_id] [-P password] [-T]

in - when copying data into sql server database table or view from file.
out - when copying data from sql server database table or view to file.

-r - Row terminator . The default it \n
-t -Field terminator . The default it \t

-S - Specify the server name to connect to the default instance of Sql Server on that server.
-U - Specify the login id to connect to Sql Server.
-P - Specify the password to connect to Sql Server.
-T - For trusted Connection.

bcp leaves.dbo.leaves out f:/leaves.txt -n -Ssystem109 -Usa -Psa1

It copies the data from leaves table to leaves.txt file.

bcp sampledb.dbo.leaves1 in f:/leaves.txt -n -Ssystem109 -Usa -Psa1

It copies the data from leaves.txt file to leaves1 table.

-n is used to use the native data types of the data. (If it was not mentioned system prompts for the data types of each field).


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: