# Import and Export SQL database to \*.sql script via SQL Management Studio

This article will show you how to export a Database to a \*.sql script and the how to import it from such kind of scripts.

## Export database to \*.sql script

1. **Right-click** on the database that should be exported.

2. "**Tasks**" -> "**Generate Scripts...**" - A *Generate and Publish Scripts* popup should appear

![GenerateScript](https://www.telerik.com/products/aspnet-ajax/documentation/assets/913bcd6e257f770168f023d6f9d57e0a/common-import-and-export-sql-script-generatescript.png)

1. On the "*Introduction*" screen click the "**Next >**" button - "*Choose Objects*" screen will appear

![GenerateAndPublishScriptsDialog-Introduction](https://www.telerik.com/products/aspnet-ajax/documentation/assets/4aba78dd200a53775cb531e52a980d35/common-import-and-export-sql-script-generateandpublishscriptsdialog-introduction.png)

1. On the "*Choose Objects*" screen you can choose whether to *export the whole database or only some of the tables*. Choose the desired objects and click "**Next >**" - "*Set Scripting Options*" screen should appear

![GenerateAndPublishScriptsDialog-ChooseObjects](https://www.telerik.com/products/aspnet-ajax/documentation/assets/6b2c72966152f8fce247b051259027c6/common-import-and-export-sql-script-generateandpublishscriptsdialog-chooseobjects.png)

1. On the "*Set Scripting Options*" you can choose whether to save or publish the script. Once you customize all the desired *save and advanced options*, click the "**Next >**" button.

![GenerateAndPublishScriptsDialog-SetScriptingOptions](https://www.telerik.com/products/aspnet-ajax/documentation/assets/e12c8d658eb4620c0c878f651324d74d/common-import-and-export-sql-script-generateandpublishscriptsdialog-setscriptingoptions.png)

* Clicking the "**Advanced**" button would allow you to customize the exported content.

```
>note **Pro tip:** From the *Advanced Scripting Options*popup, you can set "**Types of data to script**" to "**Schema and data**". That would export the database schema along with the data.

![AdvancedScriptingOptions](images/common-import-and-export-sql-script-advancedscriptingoptions.png)
```

1. On the "*Summary*" screen the options you have previously selected and if you are satisfied with them, click the "**Next >**" button.

![GenerateAndPublishScriptsDialog-Summary](https://www.telerik.com/products/aspnet-ajax/documentation/assets/f76d913d7f89a3b99e52a3c362e8ed06/common-import-and-export-sql-script-generateandpublishscriptsdialog-summary.png)

1. The database should be exported and you can find the generated \*.sql script in the location you have set in step 5.

![GenerateAndPublishScriptsDialog-SaveAndPublishScripts](https://www.telerik.com/products/aspnet-ajax/documentation/assets/a4305c5e65629ead72b1cd4987b63686/common-import-and-export-sql-script-generateandpublishscriptsdialog-saveandpublishscripts.png)

## Import database from \*.sql script

1. **Open** the \*.sql script with Microsoft SQL Server Management Studio

2. Create a new database with the name of your choice via **right-clicking** the *Databases* folder and choosing "**New Database...**". Then you *choose the name for the database* and optionally further configure the database settings.

![NewDatabase](https://www.telerik.com/products/aspnet-ajax/documentation/assets/b09d66578e48381052939e82b4fd0489/common-import-and-export-sql-script-newdatabase.png)

1. In the \*.sql script, the first two rows should be something similar to

```SQL
USE [DatabaseName]
GO
```

Here in the brackets, you can *use the name of the database* you would like to populate.

```SQL
USE [YourDatabaseName]
GO
```

1. Click the "**! Execute**" button, or use the\*\* F5\*\* shortcut for it.

![ExecuteButton](https://www.telerik.com/products/aspnet-ajax/documentation/assets/9c434b73d69e54f4a0b4441340c82f03/common-import-and-export-sql-script-executebutton.png)

1. After a successful execution of the Query, you should find your newly populated database.

![populated](https://www.telerik.com/products/aspnet-ajax/documentation/assets/f750c60518a9bb488bcc7a00955b1810/common-import-and-export-sql-script-populated.tmb-small.png)

## See Also

* [How to: Generate a Script (SQL Server Management Studio)](https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms178078%28v=sql.105%29)
