SQL Server Recovery

How to Export SQL Server Database to SQL File in 2 Simple Ways

Andrew Jackson ~ Modified: April 13th, 2023 ~ SQL Server Migration ~ 6 Minutes Reading

Export SQL Server Database to SQL File

Microsoft SQL Server is the majorly used relational database management system. It serves as a storehouse for the data that is needed for different applications on a single system or across a network. With this application, users can easily manage the database of any size. Meanwhile, users can also extract the SQL Server database in different formats. The most common is SQL Script (.sql file), this conversion of data can also be done from the SQL Server Management Studio. However, trying to export SQL Server Database to SQL file may be a headache for some users who are not familiar with the SSMS.

Therefore, in this write-up, we are going to disclose two simple and effective techniques on how to export SQL Database to SQL file without a hitch. But before going further let us take a look at a user query.

 User Query- “Hello everyone, I am new to this database and I don’t know how to export SQL Server database to SQL file. Can anyone suggest me how can I export my data into .sql file, so that I can share it with someone easily? Please assist me with a simple and actual working technique for the same.”

SQL Server Export Database to SQL File Steps

  • Open the tool & Click on Open button.
  • Select Quick Scan or Advance Scan.
  • Select destination as SQL script file.
  • Set schema or schema & data option.
  • Click on the Export to finish the task.

In this section, we will discuss some effective approaches to convert SQL database to SQL file with ease. Go through it and get the solution which is suitable for you.

Approach 1: Convert SQL Database to SQL File Using Generate Script Wizard

Follow the below-mentioned instructions to achieve the same:

Step 1. Launch MS SQL Server Management Studio on your machine. Right-click on the database you want to export and then click on Tasks>>Generate Scripts…
Step 2. A Generate and Publish Scripts Window will appear, simply press the Next button.
Step 3. On the Choose Objects page, select either Script entire database and all database objects or Select specific database objects and then click on Next.
Step 4. Now, on the Set Scripting Options Window, choose Save Scripts to a specific location and click the Advanced button to configure the additional export options. Then press the Next button.
Step 5. After that, the Summary page will appear, press the Next button.
Step 6. Finally, click the Finish button to close the Save or Publish Scripts Wizard.

Also Read: Upgrade SQL Server 2016 to 2019 Safely

Approach 2. Export SQL Server Database to SQL file Using Expert Solution

The above-mentioned method is successful if the SQL Server database is in a healthy state. In case, if you are trying to export a corrupted SQL database, then, you need to use a proficient third-party tool like SysTools SQL Server Database Migrator and export SQL Server database to script file without any hassle.

Also, this software has the potential to restore deleted database objects and provide options to export the complete or selective data to SQL Compatible Script, Live SQL Server environment or CSV format. The tool also display the complete database on its intuitive interface to ensure the correct data goes for the process. Moreover, this tool is compatible with all SQL Server versions such as SQL Server 2019, 2017, 2016, 2014, 2012, 2008, and below.

Download Now Purchase Now

Steps to Export SQL Server Database to SQL File:

Step-1. Download & launch the SQL Server Migrator tool and then click on Open to load SQL database file (.mdf file).

Hit the open button

Step-2. Choose a mode (if your database is on live server then choose Online mode or else choose Offline mode).

select mode

Step-3. Provide server name which can be detect automatically by the tool and its authentication and credentials. Click OK.

enter server details

Step-4. Here you can the see your SQL data stored in the selected database. Click on Export to proceed.

view files

Step-5. Select Scriptsor SQL Server here as per your preference. that are compatible with the server. This is crucial to export SQL Server Database to SQL file format. The software will fetch all the databases and let you select the database items which you want to export. Finally, press the Save button to begin the process.

destination path

Once the process gets completed, go to the exported location and check the converted files for each database object.

Read More: How to export data from table to CSV file in SQL server?

Approach 3. T-SQL Method for SQL Server Export Database to SQL File

If users want to export database files using the T-SQL method, the below steps can be very helpful to them.

  1. Right Click on Database > Go to Tools & Select Export Data.
  2. Select the data export option on the table level.
  3. Set the file format in which users want their export file.
  4. Here, Choose the data files that is required to export.
  5. Select the Script Generation in this step to continue.
  6. Set the Columns & Key Feilds of Import to proceed.
  7. Select a range of rows to export in the destination file.
  8. Set Errors Handling tab & then Click on the Export button.
  9. Hit the Finish button to generate the T-SQL command.
  10. Users will get three scripts for each directory. Just run them on the target database.


In this post, you have seen two methods to export SQL Server database to SQL file. One is by using SQL Server Management Studio and another by using an automated solution. But the manual method will work only for the healthy database. In case, if the database you are trying to export is corrupted, then must try an alternate solution like SysTools SQL Migrator Software to convert SQL database to SQL file with great ease.


Q-1. How to export SQL Server database to SQL file with data?

Ans: Follow these steps to export the SQL file easily:

  • Open SSMS & then connect to SQL Server instance.
  • Expand Databases & then Right Click on them.
  • Here, users need to point to the tasks simply.
  • Click the following options & then proceed.
  • Click on Import data & Hit the Export button.

Q-2. How do I save a SQL database as a file?

Ans: Connect to the SQL server using SSMS. Click on Expand databases. Right Click on the desired database & select Tasks >> Backup. Select backup type & remove last backup. Add backup file & then save it.

Q-3. How do I create a .SQL file in SQL Server?

Ans: Follow the five steps as stated to get desired results.

  • Go to Database Development perspective
  • Select File > New > SQL File option.
  • Specify the file name to continue further.
  • Click on Advanced & link the file with a profile.
  • Hit the Finish button to complete the task.

Q-4. How do I send a Microsoft SQL database file?

Ans: Using the SQL Server Management Studio, users can send a file by expanding the database & then selecting the attach option easily.