Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

This tutorial will help you to get started with SQL Azure

Getting Started with SQL Azure

Getting started with SQL Azure - Part 6: Migrating Databases to SQL Azure

Jan 12 2012 12:00AM by Paras Doshi   

Let us summarize the previous articles first:

Part 1: We defined SQL Azure and discussed advantages of SQL Azure

Part 2: We created an Azure account and created our very first SQL Azure database

Part 3: We discussed about the provisioning and the billing model of SQL Azure

Part 4: We discussed the SQL Azure architecture

Part 5: We discussed the SQL Azure security model

Now in this module, we are going to see how we can migrate SQL Server 2008 R2 database to SQL Azure. We will also discuss about options available and their pros and cons. So, by the end of this article, you would be equipped with knowledge of tools that could help you migrate your SQL Server Database to SQL Azure.

Now, there are two types of migration:

  1. Schema Migration: Here our aim is to get the DDL (Data definition language) scripts of the source SQL Server Database. In this article, I will demonstrate a schema migration process using “Generate script wizard” which is a feature available through SQL Server Management Studio.

  2. Data Migration: Once we have generated the schema in the target SQL Azure Database, the next step is to populate the tables with data. In this article, I will demonstrate a data migration process using BCP (command line utility).

Now, Generate Script Wizard and BCP are not the only option for migration process. There are other options too. At the end of the article, I would summarize other options. Therefore, based on your need – you could pick the best tool for the process.

So, let us do a schema migration through Generate Script Wizard.

Once you have provisioned a SQL Azure server, created a SQL Azure database and ready to migrate the SQL Server Database Schema (or probably a small chunk of data) to SQL Azure, you will find Generate Script Wizard that is a feature available in SQL Server Management Studio 2008 R2 to be very handy. In this article, we are going to discuss how to use Generate Script Wizard feature to migrate SQL Server database schema to SQL Azure database. So let’s get started.

Open SQL Server Management Studio 2008 R2 (I suggest you use this version or above of the SQL Server Management Studio with SQL Azure)

Enter in the correct SQL Server credentials. Now in the Object Explorer, right click on the Database >> Go to ‘Tasks’>> Select ‘generate scripts’

Launch Generate script wizard via SSMS

Now the home page of the ‘Generate script wizard’ looks like

Generate script wizard – Home page

As mentioned in the wizard, there are four steps to complete the wizard. Let’s do them step by step

Click on Next to see a ‘choose objects’ page.

Generate script wizard – choose objects

You could choose to script the entire database and database objects or alternatively just script specific database objects. For the purpose of this article, I have selected three tables that I wish to script. Once you are done, click on Next.

Now you will see a ‘scripting options’ page

Generate script wizard – scripting options

Now, here you are given the option of choosing the destination where the generated scripts could be saved. I choose to save it in a SQL file that could be later opened in a SSMS and we could easily run it against our target database. In this case, it is a SQL Azure database.

Now, let’s set some scripting options. Click on Advanced button that you see.

The first thing that you want to do select the target database type. In our case, it is a SQL Azure database. you can do that by selecting ‘SQL Azure Database’ in the ‘Script for the database engine type’:

Generate script wizard – Advanced scripting options

Notice that some of the options are being greyed out. This is because when you select the destination database engine type as ‘SQL Azure database’, features that are currently not supported by SQL Azure are greyed out and will not be scripted. Also, set “Convert UDDTs to Base Types” option as “True”.

Please note that even after selecting this option, you may run into features that are currently not supported by SQL Azure. Ideally, clear understanding of the contemporary difference between a SQL Server and a SQL Azure database is required before you start the migration process. Having said that, if you ran into error in the scripting process, you will be shown a report and you could easily rectify it. I will show a sample error report, later in this article.

In addition, Advanced lets you select the “Types of data to script”. In our case, we intend to carry out a schema migration, so we select “schema only”.

Generate script wizard–Types of data to script option

Now, ideally the Generate Script Wizard is not used to migrate data. Tools like SSIS and BCP do that better. If you are looking for Data Migration, I suggest you try out SSIS or BCP.

Now click on Ok and then in the ‘set scripting page’, select Next. You will see a page that summarizes your selections:

Generate script wizard – review your selection

Review it and then click on Next button

A successful scripting process will look like this:

Generate script wizard–result of scripting process

In case you run into any error, please click on ‘save report’ and open it. A sample report looks like:

Generate script wizard – Error report

Review the message column and after rectifying the error, try scripting it again.

We have been successful at scripting, right?

So now I double click on the .SQL file and also from the SSMS, I connect to the destination SQL Azure database and then run the script. Also, create the schema if it does not exist. This is result after the script ran successfully!

executing the script on target SQL Azure database

Voila!!! We have successfully completed the schema migration process!

Browsing the database in the object explorer to double check the success of the process:

reviewing the result on SQL Azure database

Now let us populate the ‘SalesLT.Address’ table with data using BCP!

BCP is an ideal straightforward command prompt driven tool to push data from one table to another similar table. This makes it an excellent tool to carry out data migration from SQL server to SQL Azure.

We have already migrated the schema of ‘SalesLT.Address’ table to SQL Azure. Now let us populate it with data using BCP!

Table in local SQL server 2008R2 database:

Table in local SQL server 2008R2 database

Table in SQL Azure, Before Data Migration:

Table in SQL Azure, Before Data Migration

Now to carry out the data migration, the first step is to export data out from SQL Server’s table.

The format to export table using BCP is: bcp table out filename -servername -username –password

Now here is the command in my case: bcp adventureworkslt2008r2.saleslt.address out c:\temp\datafromsqlserver.txt -c -S (local) –T

Here ‘adventureworkslt2008r2.saleslt.address’ is the table. ‘out’ states that we are exporting data out of the table. ‘c:\temp\datafromsqlserver.txt’ is the location of the text file where data will be pushed. “–S (local) –T” is to state that I want to connect to SQL Server instance named (local) and ‘–T’ is used for Windows Authentication. And if you are using SQL Server Authentication, you can specify it in the U username-S servername-P password format.

running BCP command to migrate data from SQL server to SQL Azure - I

Now, after we have exported the data from a local table, it’s time to push the data to cloud! So we will import the data to SQL Azure from the text file (we created the text file in above step, remember?!)

The format to Import table using BCP is bcp table in filename -servername -username –password

Now here is the command in my case: bcp adventureworksltaz2008r2.saleslt.address in c:\temp\datafromsqlserver.txt -c -U parassqlazure@bpqjia83ct -S tcp:bpqjia83ct.database.windows. net –P *****

running BCP command to migrate data from SQL server to SQL Azure – II

Now, Let’s see the status of the table in SQL Azure database. Were we able to push those rows (Data) to cloud?

Table in SQL Azure, After Data Migration:

Table in SQL Azure, After Data Migration

Voila! As you might have noticed that, we were able to migrate 450 rows (data) from ‘local’ table to ‘cloud’ table using BCP! It is very easy and straight forward, isn’t it? What’s more, it is an excellent tool to push many data to SQL Azure!

So, I hope you got a taste of how to migrate your SQL server database to SQL Azure – Now, let’s see what are our other options:

(This article would become ultra long if I discuss each process in step by step process, so I would point you to the article that I have written and then, summarize all options in a table. I hope you are OK with it)

Here we go:

First, there is a popular desktop application named SQL Azure migration wizard for migrating SQL Server databases to SQL Azure. However, Microsoft does not officially support it. However, it encapsulates the entire process of schema migration and data migration and the GUI is intuitive for the end user.

You can download the tool from here: http://sqlazuremw.codeplex.com/

For a step-by-step process: www.beyondrelational.com/blogs/parasdoshi/archive/2011/04/04/migrating-tsql-file-and-sql-server-2005-2008-database-to-sql-azure-using-sql-azure-migration-wizard.aspx

Second, SSIS (SQL Server Integration Services)*:* This is not a feature of SQL Azure. However, if you run SSIS on premise, you can configure the target database to be SQL Azure. And SSIS is a better control than BCP to migrate data from SQL server to SQL Azure.

[Tip: Prefer ADO.Net over OLEDB destination, as OLEDB is not supported by SQL Azure]

For a step-by-step process: http://beyondrelational.com/blogs/parasdoshi/archive/2011/07/18/how-to-use-sql-server-integration-services-ssis-to-migrate-data-from-sql-server-to-sql-azure-lt-lt-paras-doshi.aspx

Third, using SQL Azure import Export tool (Not to be Confused with SQL Server Import Export Wizard) to generate a BACPAC of a SQL Server database. And then load that BACPAC into SQL Azure. Now, BACPAC is essentially a zipped file of your ENTIRE database.

Note: When you try creating a BACPAC of your SQL Server database and if your source SQL Server database contains features that are not supported by SQL Azure. Then, the process would throw and error and you would be able to see a report of what went wrong. Once you know that, you can fix it and retry the BACPAC creation process.

Now, to generate a BACPAC of your SQL server database, you will need to install some binaries on your machine. Download details here: http://sqldacexamples.codeplex.com/

And once you generate your BACPAC, you upload it to Azure Blob storage. And then using the Import/Export tab in the SQL Azure portal (Windows Azure management portal) – you import this BACPAC and that’s how you migrate a SQL server database to SQL Azure using SQL Azure import export.

And now it’s summary time!

Note: Dac V 2.0 = SQL Azure import Export.

Summary of options available to migrate from SQL server to SQL Azure

Source: http://beyondrelational.com/blogs/parasdoshi/archive/2011/08/15/summary-sql-server-to-sql-azure-migration-lt-lt-paras-doshi.aspx

Now, up to this point, we have seen migration for SQL Server database to SQL Azure. What if we have non-SQL Server databases? No worries, the SQL Server Migration assistant tools could help you migrate MS ACCESS, MySQL and Oracle database to SQL Azure! (Just make sure, you the versions that support SQL Azure)

Conclusion:

Thus in this article, we saw how to migrate your databases to SQL Azure! Happy Migrating!


Paras Doshi
17 · 10% · 3265
5



Submit

3  Comments  

  • Hi Paras, I've read all the " Getting started with SQL Azure " articles .. and they were awesome . Thank You.

    I want to add one thing to this article though .... In the SQL SERVER 2012 Management Studio ... we do have an inbuilt option ' Deploy Database to SQL AZURE ' in TASKS of a DB. It should be a pretty straightforward migration of a DB to Azure.

    commented on Jan 25 2012 5:11PM
    Sree
    2829 · 0% · 3
  • Thank you!

    And yes, SQL server management studio 2012 has a straightforward way to deploy to Azure! Thanks for commenting here - it would be useful for others reading the article.

    btw, it's BACPAC (under the hood) that i discussed in the article.

    Again, Thanks for pointing to the SSMS 2012's feature, appreciate it.

    commented on Jan 25 2012 7:27PM
    Paras Doshi
    17 · 10% · 3265

Your Comment


Sign Up or Login to post a comment.

"Getting started with SQL Azure - Part 6: Migrating Databases to SQL Azure" rated 5 out of 5 by 5 readers
Getting started with SQL Azure - Part 6: Migrating Databases to SQL Azure , 5.0 out of 5 based on 5 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]