Skip to main content

How to Export a Microsoft SQL Server Database as a SQL Script

You can export a Microsoft SQL Server database as a SQL script using SQL Server Management Studio (SSMS). This process creates a .sql file containing the SQL commands necessary to recreate the database schema and data, which is useful for moving data...

You can export a Microsoft SQL Server database as a SQL script using SQL Server Management Studio (SSMS). This process creates a .sql file containing the SQL commands necessary to recreate the database schema and data, which is useful for moving data between servers or for manual script editing.

Before you begin

You will need:

  • Access to the database via SQL Server Management Studio (SSMS)

  • The appropriate permissions to run the "Generate scripts" wizard on the target database

  • A local or network path to save the resulting .sql file

Exporting the database as a script

  1. Open SQL Server Management Studio and connect to the database instance.

  2. In the Object Explorer pane, expand the Databases folder.

  3. Right-click the database you wish to export.

  4. Select Tasks > Generate scripts.

  5. In the Generate scripts wizard, click Next.

  6. Select the specific tables or objects you wish to export and click Next.

  7. In the Set script options page, click the Generate scripts button.

  8. In the Choose To section, select Save as or open in new query window.

  9. Specify the file path and name for the script (e.g., C:\backups\database_export.sql).

  10. Click Next.

  11. In the Generate script options page, click the Advanced button.

  12. Ensure the Types of data to save option is set to Schema and data if you want to include the actual records, or Schema only if you only want the table structures.

  13. Click OK to close the Advanced window.

  14. Click Next to begin the generation process.

  15. Once the wizard completes, click Finish.

Confirm the result

  • The wizard will complete, and the .sql file will be created at the location you specified.

  • You can verify the file by opening it in a text editor or within SSMS to ensure it contains the expected CREATE and INSERT statements.

Limitations

  • The size of the resulting .sql file depends on the amount of data in the database. Very large databases may produce scripts that are difficult to open in standard text editors.

  • This method is intended for creating scripts for migration or manual review; it is not a substitute for a full database backup.

Did this answer your question?