You are currently viewing How to import the Azure SQL database using BACPAC

How to import the Azure SQL database using BACPAC

We have created a single database with sample Adventure Works DB in one of previous articles. We also have created single database empty in Azure SQL and then added schema to it using SSMS.

We also have seen how can we export the data to BACPAC using CLI / PowerShell or Azure Portal. In this article let’s try to import the BACPAC file into the database.

If you don’t have an Azure subscription, create a free account.

For following all the steps in this article, you need to sign in to the Azure portal.

Using Azure Portal

Sign in to Azure portal and navigate to the Azure SQL Database server resource. Then you can click on Import database button from the overview panel.

After clicking on import database button, a new panel will be displayed. In new panel, you need to provide below details:

  • Subscription, under which the resource (i.e. database) will be created
  • Storage, the file name from storage container. If you click on this input control, you will be asked to select a storage account. Once you select storage account, you will be asked to select container. After selecting container, it will ask you to select the bacpac file.
  • Pricing Tier of the compute. If you click on this option, you will be asked to select the vCores and other details about compute.
  • Database name, in which the bacpac file should be imported. It is defaulted to the bacpac file name. I am keeping the default value.
  • Collation, the SQL Server database collation
  • Server admin login is username to database server
  • Password is password of the admin user

Then you can click on OK to issue the import request.

You can track progress of import operation using Import / Export history screen of the database server as shown in below snapshot. You can also see start / end time of the import / export operation by clicking on specific entry from the panel.

Once the import is complete, you can see the import operation has created a new database with name you specified during import.

Azure CLI

The below commands demonstrate how Azure CLI can be used to import the bacpac file. Please refer this page from Azure documentation for more details.

The first command gets the storage account key list. One of the key can be used in second command. This second command issues the import request.

# get the storage account key
az storage account keys list --resource-group "<resourceGroupName>" --account-name "<storageAccountName>"

az sql db import --resource-group "<resourceGroupName>" --server "<serverName>" --name "<databaseName>" `
    --storage-key-type "StorageAccessKey" --storage-key "<storageAccountKey>" `
    --storage-uri "" `
    -u "<userId>" -p $(ConvertTo-SecureString -String "<password>" -AsPlainText -Force)

I hope this article was helpful. Let me know your thoughts.

Leave a ReplyCancel reply