SQL Server database migration to SQL Database in the cloud

In this article, you learn about the two primary methods for migrating a SQL Server 2005 or later database to Azure SQL Database. The first method is simpler but requires some, possibly substantial, downtime during the migration. The second method is more complex, but substantially eliminates downtime during the migration.

In both cases, you need to ensure that the source database is compatible with Azure SQL Database using the Data Migration Assistant (DMA). SQL Database V12 is approaching feature parity with SQL Server, other than issues related to server-level and cross-database operations. Databases and applications that rely on partially supported or unsupported functions need some re-engineering to fix these incompatibilities before the SQL Server database can be migrated.

Note

To migrate a non-SQL Server database, including Microsoft Access, Sybase, MySQL Oracle, and DB2 to Azure SQL Database, see SQL Server Migration Assistant.

Method 1: Migration with downtime during the migration

Use this method if you can afford some downtime or you are performing a test migration of a production database for later migration. For a tutorial, see Migrate a SQL Server database.

The following list contains the general workflow for a SQL Server database migration using this method.

VSSSDT migration diagram

  1. Assess the database for compatibility using the latest version of Data Migration Assistant (DMA).
  2. Prepare any necessary fixes as Transact-SQL scripts.
  3. Make a transactionally consistent copy of the source database being migrated - and ensure no further changes are being made to the source database (or you can manually apply any such changes after the migration completes). There are many methods to quiesce a database, from disabling client connectivity to creating a database snapshot.
  4. Deploy the Transact-SQL scripts to apply the fixes to the database copy.
  5. Export the database copy to a BACPAC file on a local drive.
  6. Import the BACPAC file as a new Azure SQL database using any of several BACPAC import tools, with SQLPackage.exe being the recommended tool for best performance.

Optimizing data transfer performance during migration

The following list contains recommendations for best performance during the import process.

  • Choose the highest service level and performance tier that your budget allows to maximize the transfer performance. You can scale down after the migration completes to save money.
  • Minimize the distance between your BACPAC file and the destination data center.
  • Disable auto-statistics during migration
  • Partition tables and indexes
  • Drop indexed views, and recreate them once finished
  • Remove rarely queried historical data to another database and migrate this historical data to a separate Azure SQL database. You can then query this historical data using elastic queries.

Optimize performance after the migration completes

Update statistics with full scan after the migration is completed.

Method 2: Use Transactional Replication

When you cannot afford to remove your SQL Server database from production while the migration is occurring, you can use SQL Server transactional replication as your migration solution. To use this method, the source database must meet the requirements for transactional replication and be compatible for Azure SQL Database. For information about SQL replication with AlwaysOn, see Configure Replication for Always On Availability Groups (SQL Server).

To use this solution, you configure your Azure SQL Database as a subscriber to the SQL Server instance that you wish to migrate. The transactional replication distributor synchronizes data from the database to be synchronized (the publisher) while new transactions continue occur.

With transactional replication, all changes to your data or schema show up in your Azure SQL Database. Once the synchronization is complete and you are ready to migrate, change the connection string of your applications to point them to your Azure SQL Database. Once transactional replication drains any changes left on your source database and all your applications point to Azure DB, you can uninstall transactional replication. Your Azure SQL Database is now your production system.

SeedCloudTR diagram

Tip

You can also use transactional replication to migrate a subset of your source database. The publication that you replicate to Azure SQL Database can be limited to a subset of the tables in the database being replicated. For each table being replicated, you can limit the data to a subset of the rows and/or a subset of the columns.

Migration to SQL Database using Transaction Replication workflow

Important

Use the latest version of SQL Server Management Studio to remain synchronized with updates to Microsoft Azure and SQL Database. Older versions of SQL Server Management Studio cannot set up SQL Database as a subscriber. Update SQL Server Management Studio.

  1. Set up Distribution
  2. Create Publication
  3. Create Subscription

Some tips and differences for migrating to SQL Database

  1. Use a local distributor
    • This causes a performance impact on the server.
    • If the performance impact is unacceptable, you can use another server but it adds complexity in management and administration.
  2. When selecting a snapshot folder, make sure the folder you select is large enough to hold a BCP of every table you want to replicate.
  3. Snapshot creation locks the associated tables until it is complete, so schedule your snapshot appropriately.
  4. Only push subscriptions are supported in Azure SQL Database. You can only add subscribers from the source database.

Resolving database migration compatibility issues

There are a wide variety of compatibility issues that you might encounter, depending both on the version of SQL Server in the source database and the complexity of the database you are migrating. Older versions of SQL Server have more compatibility issues. Use the following resources, in addition to a targeted Internet search using your search engine of choices:

In addition to searching the Internet and using these resources, use the MSDN SQL Server community forums or StackOverflow.

Next steps