Guide on How to Export Database From SQL Server to CSV File

  author
Written By Tej Pratap Shukla
Anuraag Singh
Approved By Anuraag Singh  
Published On August 27th, 2022
Reading Time 4 Minutes Reading

No doubt, when we consider the best enterprise database systems, Microsoft SQL Server always wins the race. You can easily manage the database of any size so easily with this application. Meanwhile, users can extract SQL table data in different formats. The most popular is CSV file type. The conversion of SQL Server data to CSV can be done from the SQL Server Management Studio.

However, due to lack of knowledge, users become unable to do so. Therefore, in this technical post, we are going to show a comprehensive step-by-step guide on how to export SQL Server database to CSV file without any trouble.

So, let’s begin!

How to Export Data as CSV Format from SQL Server Using SSMS

If a user follows the below instructions carefully, then converting SQL database to CSV is a very easy method. However, it creates a problem when the primary database MDF file is corrupted.

In such scenario, you cannot convert table database in desired .csv. For this, first, repair the unhealthy primary database file to a healthy one using SysTools SQL MDF Database Recovery Tool. It is a proficient utility that scans highly corrupt MDF & NDF file and export the recovered data directly either into SQL Server database or SQL Scripts. And once you receive the healthy MDF file, then follow the below steps on how to export SQL Server table data to CSV file.

Also Read: How to Export Data from MDF to Excel?

Full Guide to Convert SQL Server Data to CSV

  • You need to open SQL Server Management Studio and connect to the database.
  • Go to the database whose data you want to export in CSV. Here, the SQL database name is ‘testing’ that consist of a table named as ‘Example1’. You can first view its data as shown in the screenshot.

convert sql query to csv

  • Now, right-click on ‘testing’ database and click on Tasks to export table data in CSV.

ms sql export query result to csv

  • Select Export data… from the Tasks menu.

extract sql data to csv

  • Once you have clicked on the option, the SQL Server Import and Export Wizard opens. Here, you need to click on the Data source drop-down button and select SQL Server Native Client 11.0. Then, hit the Next button.

export mdf file to csv

  • Under Choose a Destination page, opt for Flat File Destination to export data as CSV from SQL Server and click on Next.

sql server mdf to csv

  • On the following window, click on Browse and enter a file name in which table data will save. Also, select CSV format and click on Open.

Browse a file

  • In Choose a Destination window, you can also select Locale, Code Page, Text Qualifier. Once you have done with this, click on Next.

backup sql database to csv

  • In Specify Table Copy or Query, you have two options from which you can export the SQL database into CSV format. Either you can choose Copy data from one or more tables or views or Write a query to specify the data to transfer. Here, we opt for first option and hit the Next button.

save sql data to csv

  • Now, you can select the desired table for the conversion from Source table or view option. Plus, you can also change the default settings of Row & Column delimiter.

Change Default Settings

  • Click on Preview button to get a brief view of SQL table that is going to export into CSV. In fact, choose Edit Mappings to manage the data.

Database preview

  • You can easily view table schema along with data as shown in the screenshot.

View SQL Table Database

  • Afterward, you can either select Run immediately or select Save SSIS package to export table as CSV format from SQL Server. Then, click on Next.

convert sql database to csv

  • In Complete the Wizard window, the entire summary of export task shown on the dashboard. At last, click on Finish to initiate the process.

Summary Report

  • You can also view the live status of procedure that displays on interface.

View SQL MDF to CSV Process

  • After the completion of task, click on Report drop-down button. To save the report for future analysis, opt for Save Report to File.

Save Conversion Report

  • Save the activity file with Plain Text (*.txt) format on the system and click on Save button.

Store log report

  • This report consists details of the complete SQL database to CSV conversion. If you face some error, then check this file and see what error message convey. After that, take action according to it.

Preview your Report

Bringing It All Together

That’s all about how to export SQL Server database to CSV file without any trouble. After reading this article, the readers definitely will get enough knowledge about how to extract data in CSV from Microsoft SQL Server. Plus, we have also discussed the conversion of corrupted MDF file by first repairing it with an automated solution.

  author

By Tej Pratap Shukla

A versatile technocrat, always in the search for new and interesting areas related to technology. Works on multiple technical problems faced by users frequently. Provides the user-friendly solutions to deal with numerous technical issues.