Exporting Data Using BCP

Bradley Schacht is a Principal Program Manager on the Microsoft Fabric product team based in Saint Augustine, FL. Bradley is a former consultant, trainer, and has coauthored 6 SQL Server and Power BI books, most recently Learn Microsoft Fabric. As a member of the Microsoft Fabric product team, Bradley works directly with customers to solve some of their most complex data problems and helps shape the future of Microsoft Fabric. Bradley gives back to the community through speaking at events such as the SQLBits, Fabric Community Conference, PASS Community Data Summit, SQL Saturdays, Code Camps, and user groups across the country including locally at the Jacksonville SQL Server User Group (JSSUG). He is a contributor on SQLServerCentral.com and blogs on his personal site, BradleySchacht.com.




You can see in the screenshot the basic syntax for BCP is [What to Export] [in or out] [file] BCP AdventureWorks.Production.Product out C:Production_Product.txt The second parameter can actually have one of four values:
Query Export: BCP "SELECT * FROM AdventureWorks.Production.ProductModel" QUERYOUT C:ProductionProductModel.txt -S localhostSQL2008R2 -T -c The results in this case are similar: 128 rows exported, still under a second and 1,376 rows per second.
Notice what happens when providing a query and specifying OUT instead of QUERYOUT: Unfortunately the error is not all that great, we are just told that an error occurred while processing the command line.
Just to show what happens when exporting a table with more than just a couple of records here is a screenshot of the export from ContosoRetailDW.dbo.FactOnlineSales
Hope this sheds some light on exporting data with BCP. Be on the lookout for some information coming on importing data with BCP as well as a performance comparison between BCP and SSIS direct to a flat file. Want to explore the BCP options in more detail? Head over to the MSDN page: