SQL SERVER – Simple Example of BCP Command Line Utility

I was recently asked if I know the fastest way to export data from SQL Server table. This was very interesting question personally, as I have not run any such tests in the past. However, everytime when I had to export data, I have used in past BCP command line utility and I have found it does a pretty good job.

In this blog post we will see a working example of how BCP works.

SQL SERVER - Simple Example of BCP Command Line Utility bcp5-800x448

Step 1: Open Command Prompt

Go to run and type cmd to open command prompt in your system.

SQL SERVER - Simple Example of BCP Command Line Utility bcp1

Step 2: Change your directory context

Change your directory context to the folder where BP Utility is located

BCP Location for SQL Server 2012 – C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn

BCP Location for SQL Server 2014 – C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\120\Tools\Binn

BCP Location for SQL Server 2015 – C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn

SQL SERVER - Simple Example of BCP Command Line Utility bcp2

Step 3: Run BCP Command Line Utility

In following example, I am exploring Person. Address table of AdventureWorks2014 database. My server’s IP address is 127.0.0.1 and username is sa and password is sql. I hope this simple example helps to understand how BCP works.

bcp "Person.Address" out c:\data\Address.txt -S "127.0.0.1" -d AdventureWorks2014 -Usa -Psql -c -T

SQL SERVER - Simple Example of BCP Command Line Utility bcp3

Step 4: Open the output file

SQL SERVER - Simple Example of BCP Command Line Utility bcp4

That’s it! We are done!

As I have said, I have not done any tests, but I have found BCP to extremely fast when I have to export data and I suggest you try this out as well.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Bulk Logging, SQL Scripts, SQL Server, SQL Utility
Previous Post
SQL SERVER – SSMS Trick – Switching Columns in Grid Output
Next Post
PowerShell – Create a User with Read Rights on a Database

Related Posts

Leave a Reply