Tag Archives: export from SQL to Flat file

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

Microsoft SQL Server Blog. Fight the fear of SQL with SQLHub.com. Founder is Ritesh Shah