Featured image of post Exporting and importing an Azure SQL database

Exporting and importing an Azure SQL database

How to export an Azure SQL database to your local SQL instance

Sometimes it’s useful to be able to work with or debug data locally. Here’s a simple howto for exporting an Azure SQL database to your local SQL Server instance.

Requirements

A really quick and simple way to export the database from Azure to your local machine is to use Azure Data Studio with the Admin Pack for SQL Server extension installed.

You can install Azure Data Studio with winget:

winget install Microsoft.AzureDataStudio

Then go to Extensions. search for Admin Pack for SQL Server and install it.

Once installed, restart Azure Data Studio.

Exporting the database to a bacpac file

Connect to your Azure SQL Server instance using Azure Data Studio.

Right click the Databases section and then select Data-tier Application Wizard:

Data-tier Application Wizard

Proceed by selecting Export the schema and data from a database to the logical .bacpac file format [Export Bacpac]:

Data-tier Application Wizard Step 01

Click Next and select the server, database and the file location for the bacpac file:

Data-tier Application Wizard Step 02

Click Next to see the summary and then Export.

Data-tier Application Wizard Step 03

The export will start and you will see the progress in Tasks:

Data-tier Application Wizard In Progress

Importing the bacpac file to your local SQL Server instance

Run the following SQL query on your local SQL master database:

sp_configure 'contained database authentication', 1; 
GO  
RECONFIGURE;
GO

Then right click the Databases section and select Data-tier Application Wizard:

Data-tier Application Wizard Local

Proceed by selecting Create a database from a .bacpac file [Import Bacpac]:

Data-tier Application Wizard Import Step 01

Choose the .bacpac file, the server and the database name:

Data-tier Application Wizard Import Step 02

Review the summary and click Import:

Data-tier Application Wizard Import Step 03

An import task will start and once completed you will see the succeeded message in Tasks:

Data-tier Application Wizard Import Succeeded

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy