BCP – Export data from SQL Server to Flat file (Bulk Copy Program)

I wrote few articles for BULK INSERT, BCP but in all of those articles I have imported data from flat file to SQL Server table. But now in this article I will show you how you can export data from SQL SERVER to flat file like TXT or CSV etc.

BTW, if you want to refer my past article for BULK INSERT and BCP, please follow below given link.

For BCP:
For Bulk Insert:
Now let us move to our core topic of the article.

I will create one table in SQL Server and insert some rows in it, which I will be transfer from SQL Server’s table to text file.

–create one table for demo

use adventureworks



Name VARCHAR(50),

Dept VARCHAR(10),

Company VARCHAR(15)


–INSERT records


SELECT ‘Ritesh’,‘MIS’,‘echem’ UNION ALL


SELECT ‘Rajan’, ‘account’,‘Marwadi’ UNION ALL

SELECT ‘Alka’,‘account’,‘tata’ UNION ALL

SELECT ‘Pinal’,‘DBA’,‘sqlautho’ UNION ALL

SELECT ‘Alpesh’,‘Chemical’,‘echem’

Now let me open Command Prompt from where I can run BCP.EXE utility to export my data from SQL Server to Flat File.

Run following command in your Command Prompt (start typing command from BCP, not from “C:\>”)

C:\>BCP adventureworks.dbo.emps out c:\empTmp.txt –T –t, -r\n –c

That’s it, you are done. You will get one file name “empTmp.txt” in your “C” drive. For understanding argument of BCP command, please refer my previous article at:


Reference: Ritesh Shah

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: