Quickstart: Import a BACPAC file to a database in Azure SQL Database

You can import a SQL Server database into a database in Azure SQL Database using a BACPAC file. You can import the data from a BACPAC file stored in Azure Blob storage (standard storage only) or from local storage in an on-premises location. To maximize import speed by providing more and faster resources, scale your database to a higher service tier and compute size during the import process. You can then scale down after the import is successful.

Note

The imported database's compatibility level is based on the source database's compatibility level.

Important

After importing your database, you can choose to operate the database at its current compatibility level (level 100 for the AdventureWorks2008R2 database) or at a higher level. For more information on the implications and options for operating a database at a specific compatibility level, see ALTER DATABASE Compatibility Level. See also ALTER DATABASE SCOPED CONFIGURATION for information about additional database-level settings related to compatibility levels.

Import from a BACPAC file in the Azure portal

This section shows how, in the Azure portal, to create an Azure SQL database from a BACPAC file stored in Azure Blob storage. The portal only supports importing a BACPAC file from Azure Blob storage.

Note

A managed instance does not currently support migrating a database into an instance database from a BACPAC file using the Azure portal.

To import into a single database using the Azure portal, open the page for the database server for the single database and then, on the toolbar, select Import database.

Database import

Select the storage account, container, and BACPAC file you want to import. Specify the new database size (usually the same as origin) and provide the destination SQL Server credentials. For a list of possible values for a new Azure SQL database, see Create Database.

Monitor import's progress

To monitor an import's progress, open the database's server page, and, under Settings, select Import/Export history. When successful, the import has a Completed status.

To verify the database is live on the database server, select SQL databases and verify the new database is Online.

Import from a BACPAC file using SqlPackage

To import a SQL Server database using the SqlPackage command-line utility, see import parameters and properties. SqlPackage has the latest SQL Server Management Studio and SQL Server Data Tools for Visual Studio. You can also download the latest SqlPackage from the Microsoft download center.

For scale and performance, we recommend using SqlPackage in most production environments rather than using the Azure portal. For a SQL Server Customer Advisory Team blog about migrating using BACPAC files, see migrating from SQL Server to Azure SQL Database using BACPAC Files.

The following SqlPackage command imports the AdventureWorks2008R2 database from local storage to an Azure SQL Database server called mynewserver20170403. It creates a new database called myMigratedDatabase with a Premium service tier and a P6 Service Objective. Change these values as appropriate for your environment.

SqlPackage.exe /a:import /tcs:"Data Source=mynewserver20170403.database.windows.net;Initial Catalog=myMigratedDatabase;User Id=<your_server_admin_account_user_id>;Password=<your_server_admin_account_password>" /sf:AdventureWorks2008R2.bacpac /p:DatabaseEdition=Premium /p:DatabaseServiceObjective=P6

Important

To connect to a SQL Database server managing a single database from behind a corporate firewall, the firewall must have port 1433 open. To connect to a managed instance, you must have a point-to-site connection or an express route connection.

This example shows how to import a database using SqlPackage with Active Directory Universal Authentication.

SqlPackage.exe /a:Import /sf:testExport.bacpac /tdn:NewDacFX /tsn:apptestserver.database.windows.net /ua:True /tid:"apptest.onmicrosoft.com"

Import from a BACPAC file using PowerShell

Use the New-AzureRmSqlDatabaseImport cmdlet to submit an import database request to the Azure SQL Database service. Depending on database size, the import may take some time to complete.

$importRequest = New-AzureRmSqlDatabaseImport 
   -ResourceGroupName "<your_resource_group>" `
   -ServerName "<your_server>" `
   -DatabaseName "<your_database>" `
   -DatabaseMaxSizeBytes "<database_size_in_bytes>" `
   -StorageKeyType "StorageAccessKey" `
   -StorageKey $(Get-AzureRmStorageAccountKey -ResourceGroupName "<your_resource_group>" -StorageAccountName "<your_storage_account").Value[0] `
   -StorageUri "https://myStorageAccount.blob.core.windows.net/importsample/sample.bacpac" `
   -Edition "Standard" `
   -ServiceObjectiveName "P6" `
   -AdministratorLogin "<your_server_admin_account_user_id>" `
   -AdministratorLoginPassword $(ConvertTo-SecureString -String "<your_server_admin_account_password>" -AsPlainText -Force)

You can use the Get-AzureRmSqlDatabaseImportExportStatus cmdlet to check the import's progress. Running the cmdlet immediately after the request usually returns Status: InProgress. The import is complete when you see Status: Succeeded.

$importStatus = Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $importRequest.OperationStatusLink
[Console]::Write("Importing")
while ($importStatus.Status -eq "InProgress")
{
    $importStatus = Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $importRequest.OperationStatusLink
    [Console]::Write(".")
    Start-Sleep -s 10
}
[Console]::WriteLine("")
$importStatus

Tip

For another script example, see Import a database from a BACPAC file.

Limitations

Importing to a database in elastic pool isn't supported. You can import data into a single database and then move the database to an elastic pool.

Import using wizards

You can also use these wizards.

Next steps