diff --git a/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC01.png b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC01.png new file mode 100644 index 0000000000000..883e4775a0e6b Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC01.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC02.png b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC02.png new file mode 100644 index 0000000000000..51be1da89098e Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC02.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC03.png b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC03.png new file mode 100644 index 0000000000000..a80483830903a Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC03.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC04.png b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC04.png new file mode 100644 index 0000000000000..17103531f022f Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC04.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC05.png b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC05.png new file mode 100644 index 0000000000000..bbebe5ac73e34 Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingBACPAC05.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingDeploymentWizard01.png b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingDeploymentWizard01.png new file mode 100644 index 0000000000000..e00e39de5b49b Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingDeploymentWizard01.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingDeploymentWizard02.png b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingDeploymentWizard02.png new file mode 100644 index 0000000000000..73c2a1b2cd03f Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/MigrateUsingDeploymentWizard02.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01.png b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01.png new file mode 100644 index 0000000000000..f7f5ba23241a5 Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01b.png b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01b.png new file mode 100644 index 0000000000000..a4f883d36af5f Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01b.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01c.png b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01c.png new file mode 100644 index 0000000000000..88b7700326a8b Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01c.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage02.png b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage02.png new file mode 100644 index 0000000000000..c015cd69a8fcc Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage02.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS01.png b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS01.png new file mode 100644 index 0000000000000..883e4775a0e6b Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS01.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS02.png b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS02.png new file mode 100644 index 0000000000000..0bf3c223b869d Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS02.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS03.png b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS03.png new file mode 100644 index 0000000000000..6733ee4e23c95 Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS03.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS04.png b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS04.png new file mode 100644 index 0000000000000..a73d773db140c Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS04.png differ diff --git a/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS05.png b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS05.png new file mode 100644 index 0000000000000..89445eacc4fa8 Binary files /dev/null and b/articles/sql-database/media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS05.png differ diff --git a/articles/sql-database/sql-database-cloud-migrate.md b/articles/sql-database/sql-database-cloud-migrate.md index bbcfe6bdffa07..74f42a83dda6f 100644 --- a/articles/sql-database/sql-database-cloud-migrate.md +++ b/articles/sql-database/sql-database-cloud-migrate.md @@ -1,5 +1,5 @@ -# Migrating a database to Azure SQL Database +# Migrating a SQL Server database to Azure SQL Database -Azure SQL Database V12 brings near-complete engine compatibility with SQL Server 2014 and later. As such, the task of migrating most databases from an on-premises instance of SQL Server 2005 or greater to an Azure SQL database is much simpler. Migration for many databases is a straightforward schema and data movement operation requiring few, if any, changes to the schema and little or no re-engineering of applications. Where databases need to be changed, the scope of these changes is more confined. +Azure SQL Database V12 brings near-complete engine compatibility with SQL Server 2014 and SQL Server 2016. For compatible databases, migration to Azure SQL Database is a straightforward schema and data movement operation requiring few, if any, changes to the schema and little or no re-engineering of applications. Where databases need to be changed, the scope of these changes is more confined than with Azure SQL Database V11. -By design, server-scoped features of SQL Server are not supported by Azure SQL Database V12. Databases and applications that rely on these features will need some re-engineering before they can be migrated. While Azure SQL Database V12 improves compatibility with an on-premises SQL Server database, migration still needs to be planned and executed carefully, particularly for large and complex databases. +By design, server-scoped features of SQL Server are not supported by Azure SQL Database V12. Databases and applications that rely on these features will need some re-engineering before they can be migrated. -## Determining compatibility -To determine if your on-premises SQL Server database is compatible with Azure SQL Database V12, you can either begin the migration using one of the two methods discussed under option #1 below and see if the schema validation routines detect an incompatibility or you can use SQL Server Data Tools in Visual Studio as discussed in option #2 below to validate compatibility. If your on-premises SQL Server database has compatibility issues, you can use SQL Server Data Tools in Visual Studio or SQL Server Management Studio to address and resolve the compatibility issues. +>[AZURE.NOTE] To migrate other types of databases, including Microsoft Access, Sybase, MySQL Oracle, and DB2 to Azure SQL Database, see [SQL Server Migration Assistant](http://blogs.msdn.com/b/ssma/). -## Migration methods -There are a number of methods for migrating a compatible on-premises SQL Server database to Azure SQL Database V12. +The workflow for migrating a SQL Server database to Azure SQL Database are: -- For small to medium databases, migrating compatible SQL Server 2005 or later databases is as simple as running the Deploy Database to Microsoft Azure Database wizard in SQL Server Management Studio, provided you do not have connectivity challenges (no connectivity, low bandwidth, or timeout issues). -- For medium to large databases or when you have connectivity challenges, you can use SQL Server Management Studio to export the data and schema to a BACPAC file (stored locally or in an Azure blob) and then import the BACPAC file into your Azure SQL instance. If you store the BACPAC in an Azure blob, you can also import the BACPAC file from within the Azure portal. For more information on a BACPAC file, see [Data-tier Applications](https://msdn.microsoft.com/library/ee210546.aspx). -- For larger databases, you will achieve the best performance by migrating the schema and the data separately. You can extract the schema into a database project using SQL Server Management Studio or Visual Studio and then deploy the schema to create the Azure SQL database. You can then extract the data using BCP and then use BCP to import the data using parallel streams into the Azure SQL database. Migrating a large, complex database will take many hours regardless of the method you choose. + 1. [Determine if your database is compatible](#determine-if-your-database-is-compatible) + 2. [If not compatible, fix database compatibility issues](#fix-database-compatibility-issues) + 3. [Migrate a compatible database](#options-to-migrate-a-compatible-database-to-azure-sql-database) -### Option #1 -***Migrating a compatible database using SQL Server Management Studio *** +## Determine if your database is compatible +There are two primary methods to use to determine if your source database is compatible. +- Export Data Tier Application: This method uses a wizard in Management Studio and displays error messages on the console. +- SQLPackage.exe: [sqlpackage.exe](https://msdn.microsoft.com/library/hh550080.aspx) is a command-line utility that ships with Visual Studio and SQL Server. This method will generate a report. -SQL Server Management Studio provides two methods for migrating your compatible on-premises SQL Server database to an Azure SQL database. You can either use the Deploy Database to Microsoft Azure SQL Database wizard or export the database to a BACPAC file, which can then be imported to create a new Azure SQL database. The wizard validates Azure SQL Database V12 compatibility, extracts the schema and data into a BACPAC file and then imports it into the Azure SQL database instance specified. To use this option, see [Use SSMS](sql-database-migrate-ssms.md). +> [AZURE.NOTE] There is a third method, that will also use trace files to test for compatibility. This is [SQL Azure Migration wizard](http://sqlazuremw.codeplex.com/), a free tool on Codeplex. However, this tool currently may find compatibility errors that were issues for Azure SQL Database V11 that are not issues for Azure SQL Database V12. -### Option #2 -***Update the database schema off-line using Visual Studio and then deploy with SQL Server Management Studio*** +If database incompatibilities are detected, you will need to fix these incompatibilities before you can migrate your database to Azure SQL Database. For guidance on how to fix database compatibility issues, go to [fix database compatibility issues](#fix-database-compatibility-issues). -If your on-premises SQL Server database is not compatible or to determine if it is compatible, you can import the database schema into a Visual Studio database project for analysis. To analyze, you specify the target platform for the project as SQL Database V12 and then build the project. If the build is successful, the database is compatible. If the build fails, you can resolve the errors in SQL Server Data Tools for Visual Studio ("SSDT"). Once the project builds successfully, you can publish it back as a copy of the source database and then use the data compare feature in SSDT to copy the data from the source database to the Azure SQL V12 compatible database. This updated database is then deployed to Azure SQL Database using option #1. If schema-only migration is required, the schema can be published directly from Visual Studio directly to Azure SQL Database. Use this method when the database schema requires more changes than can be handled by the migration wizard alone. To use this option, see [Use Visual Studio](sql-database-migrate-visualstudio-ssdt.md). +> [AZURE.IMPORTANT] These options do not catch all of the compatibility issues between different levels of SQL Server databases (i.e. level 90, 100, and 110). If you are migrating from an older database (level 80, 90, 100, and 110), you should go through the upgrade process first (at least in the dev environment) and once on SQL Server 2014 or later, then migrate to Azure SQL Database. -## Deciding options to use -- If you anticipate that a database can be migrated without change you should use option #1, which is quick and easy. If you are uncertain, start by exporting a schema-only BACPAC from the database as described in option #1. If the export succeeds with no errors, you can use option #1 to migrate the database with its data. -- If you encounter errors during the export of option#1, use option #2 and correct the database schema offline in Visual Studio using a combination of the migration wizard and manually applied schema changes. A copy of the source database is then updated in situ and then migrated to Azure using option #1. +## Determine if your database is compatible using sqlpackage.exe -## Migration tools -Tools used include SQL Server Management Studio (SSMS) and the SQL Server tooling in Visual Studio (VS, SSDT), as well the Azure portal. +1. Open a command prompt and change a directory containing the newest version of sqlpackage.exe. This utility ships with both Visual Studio and SQL Server. +2. Execute the following command, substituting for the following arguments: < server_name >, < database_name >, < target_file >, < schema_name.table_name > and < output_file >. The reason for the /p:TableName argument is that we only want to test for database compability for export to Azure SQL DB V12 rather than export the data from all tables. Unfortunately, the export argument for sqlpackage.exe does not support extracting no tables, so you will need to specify a single small table. The < output_file > will contain the report of any errors. -> [AZURE.IMPORTANT] Be sure to install the latest versions of the client tools as earlier versions are not compatible with the Azure SQL Database V12. + 'sqlpackage.exe /Action:Export /ssn:< server_name > /sdn:< database_name > /tf:< target_file > /p:TableData=< schema_name.table_name > > < output_file > 2>&1' -### SQL Server Management Studio (SSMS) -SSMS can be used to deploy a compatible database directly to Azure SQL Database or to export a logical backup of the database as a BACPAC, which can then be imported, still using SSMS, to create a new Azure SQL Database. + ![Export a data-tier application from the Tasks menu](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01.png) -[Download the latest version of SSMS](https://msdn.microsoft.com/library/mt238290.aspx) +3. Open the output file and review the compatibility errors, if any. For guidance on how to fix database compatibility issues, go to [fix database compatibility issues](#fix-database-compatibility-issues). -### SQL Server tooling in Visual Studio (VS, SSDT) -The SQL Server tooling in Visual Studio can be used to create and manage a database project comprising a set of Transact-SQL files for each object in the schema. The project can be imported from a database or from a script file. Once created, the project can be to Azure SQL Database v12; building the project then validates schema compatibility. Clicking on an error opens the corresponding Transact-SQL file allowing it to be edited and the error corrected. Once all the errors are fixed the project can be published, either directly to SQL Database to create an empty database or back to (a copy of) the original SQL Server database to update its schema, which allows the database to be deployed with its data using SSMS as above. + ![Export a data-tier application from the Tasks menu](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage02.png) -Use the [latest SQL Server Data Tools for Visual Studio](https://msdn.microsoft.com/library/mt204009.aspx) with Visual Studio 2013 Update 4 or later. +## Determine if your database is compatible using Export Data Tier Application -## Comparisons -| Option #1 | Option #2 | -| ------------ | ------------ | ------------ | -| Deploy a compatible database to Azure SQL Database | Update database in-place then deploy to Azure SQL Database | -|![SSMS](./media/sql-database-cloud-migrate/01SSMSDiagram.png)| ![Offline Edit](./media/sql-database-cloud-migrate/03VSSSDTDiagram.png) | -| Uses SSMS | Uses VS and SSMS | -|Simple process requires that schema is compatible. Schema is migrated unchanged. | Schema is imported into a database project in Visual Studio. Additional updates are made using SSDT for Visual Studio and final schema used to update the database in situ. | -| Always deploys or exports the entire database. | Full control of the objects that are included in the migration. | -| No provision for changing the output if there are errors, the source schema must be compatible. | Full features of SSDT for Visual Studio available. Schema is changed offline. | Application validation occurs in Azure. Should be minimal as schema is migrated without change. | Application validation can be done in SQL Server before the database is deployed to Azure. | -| Simple, easily configured one- or two-step process. | More complex multi-step process (easier if only deploying schema). | +1. Verify that you have version 13.0.600.65 or later of SQL Server Management Studio. New versions of Management Studio are updated monthly to remain in sync with updates to the Azure portal. + + > [AZURE.IMPORTANT] Download the [latest](https://msdn.microsoft.com/library/mt238290.aspx) version of SQL Server Management Studio. It is recommended that you always use the latest version of Management Studio. + +2. Open Management Studio and connect to your source database in Object Explorer. +3. Right-click the source database in the Object Explorer, point to **Tasks**, and click **Export Data-Tier Application…** + + ![Export a data-tier application from the Tasks menu](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS01.png) + +4. In the export wizard, on the **Settings** tab, configure the export to save the BACPAC file to either a local disk location or to an Azure blob. A BACPAC file will only be saved if you have no database compatibility issues. If there are compatibility issues, they will be displayed on the console. + + ![Export settings](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS02.png) + +5. Click the **Advanced tab** and clear the **Select All** checkbox to skip exporting data. Our goal at this point is only to test for compatibility. + + ![Export settings](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS03.png) + +6. Click **Next** and then click **Finish**. Database compatibility issues, if any, will appear after the wizard validates the schema. + + ![Export settings](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS04.png) + +7. If no errors appear, your database is compatible and you are ready to migrate. If you have errors, you will need to fix them. To see the errors, click **Error** for **Validating schema**. For how to fix these errors, go to [fix database compatibility issues](#fix-database-compatibility-issues). + + ![Export settings](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS05.png) + +## Options to migrate a compatible database to Azure SQL Database + +- For small to medium databases, migrating a [compatible](#determine-if-your-database-is-compatible) SQL Server 2005 or later database is as simple as running the [Deploy Database to Microsoft Azure Database Wizard](#use-the-deploy-database-to-microsoft-azure-database-wizard) in SQL Server Management Studio. If you have connectivity challenges (no connectivity, low bandwidth, or timeout issues), you can [use a BACPAC to migrate](#use-a-bacpac-to-migrate-a-database-to-azure-sql-database) a SQL Server database to Azure SQL Database. +- For medium to large databases or when you have connectivity challenges, [use a BACPAC to migrate](#use-a-bacpac-to-migrate-a-database-to-azure-sql-database) a SQL Server database to Azure SQL Database. With this method, you use SQL Server Management Studio to export the data and schema to a [BACPAC](https://msdn.microsoft.com/library/ee210546.aspx#Anchor_4) file (stored locally or in an Azure blob) and then import the BACPAC file into your Azure SQL instance. If you store the BACPAC in an Azure blob, you can also import the BACPAC file from within the [Azure portal](sql-database-import.md) or [using PowerShell](sql-database-import-powershell.md). +- For larger databases, you will achieve the best performance by migrating the schema and the data separately. With this method, you script the schema using SQL Server Management Studio or create a database project in Visual Studio and then deploy the schema to Azure SQL Database. After the schema has been imported into Azure SQL Database, you then use [BCP](https://msdn.microsoft.com/library/ms162802.aspx) to extract the data into flat files and then import these files into Azure SQL Database. + + ![SSMS migration diagram](./media/sql-database-migrate-ssms/01SSMSDiagram.png) + +## Use Deploy Database to Microsoft Azure Database Wizard + +The Deploy Database to Microsoft Azure Database wizard in SQL Server Management Studio migrates a migrating a [compatible](#determine-if-your-database-is-compatible) SQL Server 2005 or later database directly to your Azure SQL logical server instance. + +> [AZURE.NOTE] The steps below assume that you have already provisioned your Azure SQL logical instance and have the connection information on hand. + +1. Verify that you have version 13.0.600.65 or later of SQL Server Management Studio. New versions of Management Studio are updated monthly to remain in sync with updates to the Azure portal. + + > [AZURE.IMPORTANT] Download the [latest](https://msdn.microsoft.com/library/mt238290.aspx) version of SQL Server Management Studio. It is recommended that you always use the latest version of Management Studio. + +2. Open Management Studio and connect to your source database in Object Explorer. +3. Right-click the source database in the Object Explorer, point to **Tasks**, and click **Deploy Database to Microsoft Azure SQL Database…** + + ![Deploy to Azure from Tasks menu](./media/sql-database-cloud-migrate/MigrateUsingDeploymentWizard01.png) + +4. In the deployment wizard, configure the connection to your Azure SQL Database server. +5. Provide the **New database name** for the database on Azure SQL DB, set the **Edition of Microsoft Azure SQL Database** (service tier), **Maximum database size**, **Service Objective** (performance level), and **Temporary file name** for the BACPAC file that this wizard creates during the migration process. See [Azure SQL Database service tiers](sql-database-service-tiers.md) for more information on service tiers and performance levels. + + ![Export settings](./media/sql-database-cloud-migrate/MigrateUsingDeploymentWizard02.png) + +6. Complete the wizard to migrate the database. Depending on the size and complexity of the database, deployment may take from a few minutes to many hours. +7. Using Object Explorer, connect to your migrated database in your Azure SQL Database server. +8. Using the Azure Portal, view your database and its properties. + +## Use a BACPAC to Migrate a SQL Server Database to Azure SQL Database + +For medium to large databases or when you have connectivity challenges, you can separate the migration process into two discrete steps. You can export of the schema and its data into a [BACPAC](https://msdn.microsoft.com/library/ee210546.aspx#Anchor_4) file using one or two methods. + +- [Export to a BACPAC file using SQL Server Management Studio](#export-a-compatible-sql-server-database-to-a-bacpac-file-using-sql-server-management-studio) +- [Export to a BACPAC using SqlPackage](#export-a-compatible-sql-server-database-to-a-bacpac-file-using-sqlpackage) + +You can store this BACPAC locally or in an Azure blob. You can then import this BACPAC file into Azure SQL Database using one of several methods. + +- [Import from a BACPAC file into Azure SQL Database using SQL Server Management Studio](#import-from-a-bacpac-file-into-azure-sql-database-using-sql-server-management-studio) +- [Import from a BACPAC file into Azure SQL Database using SqlPackage](#import-from-a-bacpac-file-into-azure-sql-database-using-sqlpackage) +- [Import from a BACPAC file into Azure SQL Database using the Azure portal](sql-database-import.md) +- [Import from a BACPAC file into Azure SQL Database using or PowerShell](sql-database-import-powershell.md) + +## Export a compatible SQL Server database to a BACPAC file using SQL Server Management Studio + +Use the steps below to use Management Studio to export a migrating a [compatible](#determine-if-your-database-is-compatible) SQL Server database to a BACPAC file. + +1. Verify that you have version 13.0.600.65 or later of SQL Server Management Studio. New versions of Management Studio are updated monthly to remain in sync with updates to the Azure portal. + + > [AZURE.IMPORTANT] Download the [latest](https://msdn.microsoft.com/library/mt238290.aspx) version of SQL Server Management Studio. It is recommended that you always use the latest version of Management Studio. + +2. Open Management Studio and connect to your source database in Object Explorer. + + ![Export a data-tier application from the Tasks menu](./media/sql-database-cloud-migrate/MigrateUsingBACPAC01.png) + +3. Right-click the source database in the Object Explorer, point to **Tasks**, and click **Export Data-Tier Application…** + + ![Export a data-tier application from the Tasks menu](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSSMS01.png) + +4. In the export wizard, configure the export to save the BACPAC file to either a local disk location or to an Azure blob. The exported BACPAC always includes the complete database schema and, by default, data from all the tables. Use the Advanced tab if you want to exclude data from some or all of the tables. You might, for example, choose to export only the data for reference tables rather than from all tables. + + ![Export settings](./media/sql-database-cloud-migrate/MigrateUsingBACPAC02.png) + +## Export a compatible SQL Server database to a BACPAC file using SqlPackage + +Use the steps below to use the [SqlPackage.exe](https://msdn.microsoft.com/library/hh550080.aspx) command line utility to export a migrating a [compatible](#determine-if-your-database-is-compatible) database to a BACPAC file. + +> [AZURE.NOTE] The steps below assume that you have already provisioned an Azure SQL Database server, have the connection information on hand, and have verified that your source database is compatible. + +1. Open a command prompt and change a directory containing the sqlpackage.exe command line utility - this utility ships with both Visual Studio and SQL Server. +2. Execute the following command, substituting for the following arguments: < server_name >, < database_name >, and < target_file >. + + 'sqlpackage.exe /Action:Export /ssn:< server_name > /sdn:< database_name > /tf:< target_file > + + ![Export a data-tier application from the Tasks menu](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01b.png) + +## Import from a BACPAC file into Azure SQL Database using SQL Server Management Studio + +Use the steps below to import from a BACPAC file into Azure SQL Database. + +> [AZURE.NOTE] The steps below assume that you have already provisioned your Azure SQL logical instance and have the connection information on hand. + +1. Verify that you have version 13.0.600.65 or later of SQL Server Management Studio. New versions of Management Studio are updated monthly to remain in sync with updates to the Azure portal. + + > [AZURE.IMPORTANT] Download the [latest](https://msdn.microsoft.com/library/mt238290.aspx) version of SQL Server Management Studio. It is recommended that you always use the latest version of Management Studio. + +2. Open Management Studio and connect to your source database in Object Explorer. + + ![Export a data-tier application from the Tasks menu](./media/sql-database-cloud-migrate/MigrateUsingBACPAC01.png) + + Once the BACPAC has been created, connect to your Azure SQL Database server, right-click the **Databases** folder and click **Import Data-tier Application...** + + ![Import data-tier application menu item](./media/sql-database-cloud-migrate/MigrateUsingBACPAC03.png) + +3. In the import wizard, choose the BACPAC file you just exported to create the new database in Azure SQL Database. + + ![Import settings](./media/sql-database-cloud-migrate/MigrateUsingBACPAC04.png) + +4. Provide the **New database name** for the database on Azure SQL DB, set the **Edition of Microsoft Azure SQL Database** (service tier), **Maximum database size** and **Service Objective** (performance level). + + ![Database settings](./media/sql-database-cloud-migrate/MigrateUsingBACPAC05.png) + +5. Click **Next** and then click **Finish** to import the BACPAC file into a new database in the Azure SQL Database server. + +6. Using Object Explorer, connect to your migrated database in your Azure SQL Database server. + +7. Using the Azure Portal, view your database and its properties. + +## Import from a BACPAC file into Azure SQL Database using SqlPackage + +Use the steps below to use the [SqlPackage.exe](https://msdn.microsoft.com/library/hh550080.aspx) command line utility to import a compatible SQL Server database (or Azure SQL database) from a BACPAC file. + +> [AZURE.NOTE] The steps below assume that you have already provisioned an Azure SQL Database server and have the connection information on hand. + +1. Open a command prompt and change a directory containing the sqlpackage.exe command line utility - this utility ships with both Visual Studio and SQL Server. +2. Execute the following command, substituting for the following arguments: < server_name >, < database_name >, < user_name >, < password > , and < source_file >. + + 'sqlpackage.exe /Action:Import /tsn:< server_name > /tdn:< database_name > /tu:< user_name > /tp:< password > /sf:< target_file > + + ![Export a data-tier application from the Tasks menu](./media/sql-database-cloud-migrate/TestForCompatibilityUsingSQLPackage01c.png) + + +## Fix database compatibility issues + +If you determine that your source SQL Server database is not compatible, you have a number of options to fix the database compatibility issues that you [identified previously](#determine-if-your-database-is-compatible). + +- Use the [SQL Azure Migration wizard](http://sqlazuremw.codeplex.com/). You can use this Codeplex tool to generate a T-SQL script from an incompatible source database that is then transformed by the wizard to make it compatible with the SQL Database and then connect to Azure SQL Database to execute the script. This tool will also analyze trace files to determine compatiblity issues. The script can be generated with schema only or can include data in BCP format. Additional documentation, including step-by-step guidance is available on Codeplex at [SQL Azure Migration wizard](http://sqlazuremw.codeplex.com/). + + ![SAMW migration diagram](./media/sql-database-cloud-migrate/02SAMWDiagram.png) + + > [AZURE.NOTE] Note that not all incompatible schema that can be detected by the wizard can be processed by its built-in transformations. Incompatible script that cannot be addressed will be reported as errors, with comments injected into the generated script. If many errors are detected, use either Visual Studio or SQL Server Management Studio to step through and fix each error that could not be fixed using the SQL Server Migration Wizard. + +- Use Visual Studio. You can use Visual Studio to import the database schema into a Visual Studio database project for analysis. To analyze, you specify the target platform for the project as SQL Database V12 and then build the project. If the build is successful, the database is compatible. If the build fails, you can resolve the errors in SQL Server Data Tools for Visual Studio ("SSDT"). Once the project builds successfully, you can publish it back as a copy of the source database and then use the data compare feature in SSDT to copy the data from the source database to the Azure SQL V12 compatible database. This updated database is then deployed to Azure SQL Database using the options [discussed previously](#options-to-migrate-a-compatible-database-to-azure-sql-database). + + ![VSSSDT migration diagram](./media/sql-database-cloud-migrate/03VSSSDTDiagram.png) + + > [AZURE.NOTE] If schema-only migration is required, the schema can be published directly from Visual Studio directly to Azure SQL Database. Use this method when the database schema requires more changes than can be handled by the migration wizard alone. + +- SQL Server Management Studio. You can fix the issues in Management Studio using various Transact-SQL commands, such as **ALTER DATABASE**.