- Article
- 8 minutes to read
This article shows how to move data from a SQL Server database to Azure SQL Database via Azure Blob Storage using the Azure Data Factory (ADF): this method is a supported legacy approach that has the advantages of a replicated staging copy, though we suggest to look at our data migration page for the latest options.
For a table that summarizes various options for moving data to an Azure SQL Database, see Move data to an Azure SQL Database for Azure Machine Learning.
Introduction: What is ADF and when should it be used to migrate data?
Azure Data Factory is a fully managed cloud-based data integration service that orchestrates and automates the movement and transformation of data. The key concept in the ADF model is pipeline. A pipeline is a logical grouping of Activities, each of which defines the actions to perform on the data contained in Datasets. Linked services are used to define the information needed for Data Factory to connect to the data resources.
With ADF, existing data processing services can be composed into data pipelines that are highly available and managed in the cloud. These data pipelines can be scheduled to ingest, prepare, transform, analyze, and publish data, and ADF manages and orchestrates the complex data and processing dependencies. Solutions can be quickly built and deployed in the cloud, connecting a growing number of on-premises and cloud data sources.
Consider using ADF:
- when data needs to be continually migrated in a hybrid scenario that accesses both on-premises and cloud resources
- when the data needs transformations or have business logic added to it when being migrated.
ADF allows for the scheduling and monitoring of jobs using simple JSON scripts that manage the movement of data on a periodic basis. ADF also has other capabilities such as support for complex operations. For more information on ADF, see the documentation at Azure Data Factory (ADF).
The Scenario
We set up an ADF pipeline that composes two data migration activities. Together they move data on a daily basis between a SQL Server database and Azure SQL Database. The two activities are:
- Copy data from a SQL Server database to an Azure Blob Storage account
- Copy data from the Azure Blob Storage account to Azure SQL Database.
Note
The steps shown here have been adapted from the more detailed tutorial provided by the ADF team: Copy data from a SQL Server database to Azure Blob storage References to the relevant sections of that topic are provided when appropriate.
Prerequisites
This tutorial assumes you have:
- An Azure subscription. If you do not have a subscription, you can sign up for a free trial.
- An Azure storage account. You use an Azure storage account for storing the data in this tutorial. If you don't have an Azure storage account, see the Create a storage account article. After you have created the storage account, you need to obtain the account key used to access the storage. See Manage storage account access keys.
- Access to an Azure SQL Database. If you must set up an Azure SQL Database, the topic Getting Started with Microsoft Azure SQL Database provides information on how to provision a new instance of an Azure SQL Database.
- Installed and configured Azure PowerShell locally. For instructions, see How to install and configure Azure PowerShell.
Note
This procedure uses the Azure portal.
Upload the data to your SQL Server instance
We use the NYC Taxi dataset to demonstrate the migration process. The NYC Taxi dataset is available, as noted in that post, on Azure blob storage NYC Taxi Data. The data has two files, the trip_data.csv file, which contains trip details, and the trip_far.csv file, which contains details of the fare paid for each trip. A sample and description of these files are provided in NYC Taxi Trips Dataset Description.
You can either adapt the procedure provided here to a set of your own data or follow the steps as described by using the NYC Taxi dataset. To upload the NYC Taxi dataset into your SQL Server database, follow the procedure outlined in Bulk Import Data into SQL Server database.
Create an Azure Data Factory
The instructions for creating a new Azure Data Factory and a resource group in the Azure portal are provided Create an Azure Data Factory. Name the new ADF instance adfdsp and name the resource group created adfdsprg.
Install and configure Azure Data Factory Integration Runtime
The Integration Runtime is a customer-managed data integration infrastructure used by Azure Data Factory to provide data integration capabilities across different network environments. This runtime was formerly called "Data Management Gateway".
To set up, follow the instructions for creating a pipeline
Create linked services to connect to the data resources
A linked service defines the information needed for Azure Data Factory to connect to a data resource. We have three resources in this scenario for which linked services are needed:
- On-premises SQL Server
- Azure Blob Storage
- Azure SQL Database
The step-by-step procedure for creating linked services is provided in Create linked services.
Define and create tables to specify how to access the datasets
Create tables that specify the structure, location, and availability of the datasets with the following script-based procedures. JSON files are used to define the tables. For more information on the structure of these files, see Datasets.
Note
You should execute the Add-AzureAccount
cmdlet before executing the New-AzureDataFactoryTable cmdlet to confirm that the right Azure subscription is selected for the command execution. For documentation of this cmdlet, see Add-AzureAccount.
The JSON-based definitions in the tables use the following names:
- the table name in the SQL Server is nyctaxi_data
- the container name in the Azure Blob Storage account is containername
Three table definitions are needed for this ADF pipeline:
- SQL on-premises Table
- Blob Table
- SQL Azure Table
Note
These procedures use Azure PowerShell to define and create the ADF activities. But these tasks can also be accomplished using the Azure portal. For details, see Create datasets.
SQL on-premises Table
The table definition for the SQL Server is specified in the following JSON file:
{ "name": "OnPremSQLTable", "properties": { "location": { "type": "OnPremisesSqlServerTableLocation", "tableName": "nyctaxi_data", "linkedServiceName": "adfonpremsql" }, "availability": { "frequency": "Day", "interval": 1, "waitOnExternal": { "retryInterval": "00:01:00", "retryTimeout": "00:10:00", "maximumRetry": 3 } } }}
The column names were not included here. You can subselect on the column names by including them here (for details check the ADF documentation topic.
Copy the JSON definition of the table into a file called onpremtabledef.json file and save it to a known location (here assumed to be C:\temp\onpremtabledef.json). Create the table in ADF with the following Azure PowerShell cmdlet:
New-AzureDataFactoryTable -ResourceGroupName ADFdsprg -DataFactoryName ADFdsp –File C:\temp\onpremtabledef.json
Blob Table
Definition for the table for the output blob location is in the following (this maps the ingested data from on-premises to Azure blob):
{ "name": "OutputBlobTable", "properties": { "location": { "type": "AzureBlobLocation", "folderPath": "containername", "format": { "type": "TextFormat", "columnDelimiter": "\t" }, "linkedServiceName": "adfds" }, "availability": { "frequency": "Day", "interval": 1 } }}
Copy the JSON definition of the table into a file called bloboutputtabledef.json file and save it to a known location (here assumed to be C:\temp\bloboutputtabledef.json). Create the table in ADF with the following Azure PowerShell cmdlet:
New-AzureDataFactoryTable -ResourceGroupName adfdsprg -DataFactoryName adfdsp -File C:\temp\bloboutputtabledef.json
SQL Azure Table
Definition for the table for the SQL Azure output is in the following (this schema maps the data coming from the blob):
{ "name": "OutputSQLAzureTable", "properties": { "structure": [ { "name": "column1", "type": "String"}, { "name": "column2", "type": "String"} ], "location": { "type": "AzureSqlTableLocation", "tableName": "your_db_name", "linkedServiceName": "adfdssqlazure_linked_servicename" }, "availability": { "frequency": "Day", "interval": 1 } }}
Copy the JSON definition of the table into a file called AzureSqlTable.json file and save it to a known location (here assumed to be C:\temp\AzureSqlTable.json). Create the table in ADF with the following Azure PowerShell cmdlet:
New-AzureDataFactoryTable -ResourceGroupName adfdsprg -DataFactoryName adfdsp -File C:\temp\AzureSqlTable.json
Define and create the pipeline
Specify the activities that belong to the pipeline and create the pipeline with the following script-based procedures. A JSON file is used to define the pipeline properties.
- The script assumes that the pipeline name is AMLDSProcessPipeline.
- Also note that we set the periodicity of the pipeline to be executed on daily basis and use the default execution time for the job (12 am UTC).
Note
The following procedures use Azure PowerShell to define and create the ADF pipeline. But this task can also be accomplished using theAzure portal. For details, see Create pipeline.
Using the table definitions provided previously, the pipeline definition for the ADF is specified as follows:
{ "name": "AMLDSProcessPipeline", "properties": { "description" : "This pipeline has two activities: the first one copies data from SQL Server to Azure Blob, and the second one copies from Azure Blob to Azure Database Table", "activities": [ { "name": "CopyFromSQLtoBlob", "description": "Copy data from SQL Server to blob", "type": "CopyActivity", "inputs": [ {"name": "OnPremSQLTable"} ], "outputs": [ {"name": "OutputBlobTable"} ], "transformation": { "source": { "type": "SqlSource", "sqlReaderQuery": "select * from nyctaxi_data" }, "sink": { "type": "BlobSink" } }, "Policy": { "concurrency": 3, "executionPriorityOrder": "NewestFirst", "style": "StartOfInterval", "retry": 0, "timeout": "01:00:00" } }, { "name": "CopyFromBlobtoSQLAzure", "description": "Push data to Sql Azure", "type": "CopyActivity", "inputs": [ {"name": "OutputBlobTable"} ], "outputs": [ {"name": "OutputSQLAzureTable"} ], "transformation": { "source": { "type": "BlobSource" }, "sink": { "type": "SqlSink", "WriteBatchTimeout": "00:5:00", } }, "Policy": { "concurrency": 3, "executionPriorityOrder": "NewestFirst", "style": "StartOfInterval", "retry": 2, "timeout": "02:00:00" } } ] }}
Copy this JSON definition of the pipeline into a file called pipelinedef.json file and save it to a known location (here assumed to be C:\temp\pipelinedef.json). Create the pipeline in ADF with the following Azure PowerShell cmdlet:
New-AzureDataFactoryPipeline -ResourceGroupName adfdsprg -DataFactoryName adfdsp -File C:\temp\pipelinedef.json
Start the Pipeline
The pipeline can now be run using the following command:
Set-AzureDataFactoryPipelineActivePeriod -ResourceGroupName ADFdsprg -DataFactoryName ADFdsp -StartDateTime startdateZ –EndDateTime enddateZ –Name AMLDSProcessPipeline
The startdate and enddate parameter values need to be replaced with the actual dates between which you want the pipeline to run.
Once the pipeline executes, you should be able to see the data show up in the container selected for the blob, one file per day.
We have not leveraged the functionality provided by ADF to pipe data incrementally. For more information on how to do this and other capabilities provided by ADF, see the ADF documentation.
Contributors
This article is maintained by Microsoft. It was originally written by the following contributors.
Principal author:
- Mark Tabladillo | Senior Cloud Solution Architect
To see non-public LinkedIn profiles, sign in to LinkedIn.
FAQs
How do I transfer data from SQL Server to SQL Azure? ›
Open the Azure SQL Migration extension for Azure Data Studio. Connect to your source SQL Server instance. Click the Migrate to Azure SQL button, in the Azure SQL Migration wizard in Azure Data Studio. Select databases for assessment, then click on next.
How does Azure data/factory connect to SQL Server? ›- Browse to the Manage tab in your Azure Data Factory or Synapse workspace and select Linked Services, then click New: Azure Data Factory. ...
- Search for SQL and select the SQL Server connector.
- Configure the service details, test the connection, and create the new linked service.
- On the File menu, select Connect to SQL Azure (this option is enabled after the creation of a project). ...
- In the connection dialog box, enter or select the server name of Azure SQL Database.
- Enter, select, or Browse the Database name.
- Enter or select Username.
- Enter the Password.
- Log on to the Azure Platform Management Portal.
- Click New > Data Services > SQL Database > Import. ...
- Navigate to the . ...
- Specify a name for the new SQL database. ...
- Specify Subscription, Edition, Max Size, and host Server details. ...
- Specify login details for the host server.
Azure SQL Database also scales for OLTP, as different pricing tiers typically scale to give you more query throughput and not so much data (the current maximum is 1TB, and in some regions 4TB). Azure SQL Data Warehouse is optimized for performing data analytics tasks, and working with large amounts of data.
What is the difference between SQL Database and SQL Server in Azure? ›SQL Database has some additional features that are not available in SQL Server, such as built-in high availability, intelligence, and management. Azure SQL Database offers the following deployment options: As a single database with its own set of resources managed via a logical SQL server.
How do you set up Azure Data Sync between Azure SQL databases and on premises SQL Server? ›- Go to the Azure portal to find your database in SQL Database. ...
- Select the database you want to use as the hub database for Data Sync. ...
- On the SQL database menu for the selected database, select Sync to other databases.
- On the Sync to other databases page, select New Sync Group.
Create an Azure SQL Database linked service
Select on the Azure SQL Database tile and select continue. In the SQL DB configuration pane, enter 'SQLDB' as your linked service name. Enter in your credentials to allow data factory to connect to your database.
...
Connect to a SQL Server
- Server Name: Enter server name here. For example, localhost.
- Authentication Type: SQL Login.
- User name: User name for the SQL Server.
- Password: Password for the SQL Server.
- Database Name: <Default>
- Server Group: <Default>
You can use Transact-SQL, command-line tools, and wizards to import and export data in SQL Server and Azure SQL Database in a variety of data formats.
What is the only prerequisite for connecting to a database in Azure SQL Database? ›
Prerequisites. To complete this quickstart, you need Azure Data Studio, and an Azure SQL Database server. If you don't have an Azure SQL server, complete one of the following Azure SQL Database quickstarts.
Can we connect Azure SQL Database from SSMS? ›Connect to your database
To continue utilizing Azure Active Directory authentication with MFA, you need SSMS 18.6 or later. In SSMS, connect to your server. A server listens on port 1433. To connect to a server from behind a corporate firewall, the firewall must have this port open.
The Azure SQL Database option is the most modern solution from Microsoft for SQL databases, and it is available only through Microsoft Azure. Unlike the Azure SQL Server Managed Instance Option, in this implementation, you only have to manage the databases and some of the features in SQL Server like logins.
How do you copy data from BLOB storage to SQL database by using Azure data factory? ›- Create a data factory.
- Create Azure Storage and Azure SQL Database linked services.
- Create Azure Blob and Azure SQL Database datasets.
- Create a pipeline containing a copy activity.
- Start a pipeline run.
- Monitor the pipeline and activity runs.
- Step 1: explore database compatibility. ...
- Step 2: select the right Azure service model. ...
- Step 3: choose your Azure service tier. ...
- Step 4: identify your required disaster recovery level. ...
- Step 5: devise a migration strategy. ...
- Step 6: migrate a test database.
With Azure Data Factory, it's fast and easy to build code-free or code-centric ETL and ELT processes.
Is Azure data/factory ETL or ELT? ›With Azure Data Factory, it is fast and easy to build code-free or code-centric ETL and ELT processes.
Can SQL Server be used as data warehouse? ›You can use SQL Server as your data warehouse but be careful of runaway costs. It can also be difficult to tune your data warehouse performance and merge data from different database types in SQL Server.
What is a key benefit of using Azure SQL Database compared to using SQL Server on-premises? ›Azure SQL allows you to benefit from almost unlimited cloud scalability and has high availability out of the box. If you also need full control over the operating system or compatibility with on-premises workloads such as SQL Server Reporting Services you can run SQL Server on an Azure VM.
Is Azure SQL Database SQL Server? ›Azure SQL Database is based on the latest stable version of the Microsoft SQL Server database engine. You can use advanced query processing features, such as high-performance in-memory technologies and intelligent query processing.
What version of SQL Server is Azure SQL Database? ›
Azure SQL Database shares the SQL Server 2016 codebase. It is compatible with SQL Server 2014 and 2016 and most of the features available in SQL Server 2016 are available in Azure SQL Database.
How do I connect Azure data Factory to an Azure SQL Database using a private endpoint? ›- Go to the Manage tab.
- Go to the Managed private endpoints section.
- Select + New under Managed private endpoints.
- Select the Azure SQL Database tile from the list, and select Continue.
- Enter the name of the SQL server you selected.
- Select Create.
- Run ApexSQL Data Diff.
- In the New project window, under the Data sources tab, set the source and destination database:
- Go to the Options tab if there is a need to set a specific comparison or synchronization option.
- In Windows, search for ODBC Data Sources, and open the ODBC Data Sources desktop app.
- Select Add.
- Select ODBC Driver 17 for SQL Server then Finish.
- Enter a name and description for the connection and the cluster you want to connect to, then select Next.
Data Factory supports three types of activities: data movement activities, data transformation activities, and control activities.
How to copy data from one server to another in SQL Server using query? ›- First of all, launch the SQL Server Management Studio from Object Explorer and connect to the Source Server.
- Right-click on the database, select the option Tasks and then choose the Copy Database option.
- Open the table with columns you want to copy and the one you want to copy into by right-clicking the tables, and then clicking Design.
- Click the tab for the table with the columns you want to copy and select those columns.
- From the Edit menu, click Copy.
Azure Data Factory (ADF) makes it very easy to connect with on-premises SQL Server and copy the data to Cloud. You just simply need to create Self-hosted Integration Runtime (IR) in your local machine which will allow you to access the data.
How do I import an SQL database into Azure Data Studio? ›To start SQL Server Import, first make a connection to a server in the Servers tab. After you make a connection, drill down to the target database that you want to import a file into a SQL table. Right-click on the database and select Import Wizard.
How do I access Azure from SQL Server? ›- Go to the Azure portal to connect to a VM. ...
- Select the virtual machine from the list.
- At the beginning of the virtual machine page, select Connect.
- On the Connect to virtual machine page, select RDP, and then select the appropriate IP address and Port number.
Does Azure SQL support SQL Server authentication? ›
Authentication. Authentication is the process of proving the user is who they claim to be. Azure SQL Database and SQL Managed Instance support SQL authentication and Azure AD authentication. SQL Managed instance additionally supports Windows Authentication for Azure AD principals.
Which protocol does Azure connect to SQL? ›Azure SQL Database supports only the tabular data stream (TDS) protocol, which requires the database to be accessible over only the default port of TCP/1433.
Which port is used for connectivity to Azure SQL? ›For connections to use this mode, clients need to allow outbound communication from the client to Azure SQL Database gateway IP addresses on port 1433.
How do I connect SQL database to SQL Azure database? ›- On the File menu, select Connect to SQL Azure (this option is enabled after the creation of a project). ...
- In the connection dialog box, enter or select the server name of Azure SQL Database.
- Enter, select, or Browse the Database name.
- Enter or select Username.
- Enter the Password.
Specifically, Azure SQL Edge doesn't support SQL Server components like Analysis Services, Reporting Services, Integration Services, Master Data Services, Machine Learning Services (In-Database), and Machine Learning Server (standalone).
How do I deploy SQL Server database to Azure? ›- On the machine where your website database is restored, open your SQL Server Management Studio.
- Locate your database, right click on it, and select Tasks » Deploy Database to Microsoft Azure SQL Database.
- On the next screen, click Next.
PRO TIP: No, Azure SQL Database is not the same as SQL Server. While they are both relational database management systems, there are key differences between the two. Azure SQL Database is a cloud-based service, while SQL Server is an on-premises software.
How do you set up Azure Data Sync between Azure SQL databases and on-premises SQL Server? ›- Go to the Azure portal to find your database in SQL Database. ...
- Select the database you want to use as the hub database for Data Sync. ...
- On the SQL database menu for the selected database, select Sync to other databases.
- On the Sync to other databases page, select New Sync Group.
This is part of performance testing Azure vs On Premise. Running one transaction with 400 changes runs faster in Azure than on Prem. But running 400 transactions with one change or 10 changes is slower in Azure.
How do I access Azure Blob storage from SQL Server? ›- Connect to SQL Server Management Studio.
- Open a new query window and connect to the SQL Server 2016 instance of the database engine in your Azure virtual machine.
- Open Object Explorer and connect to Azure storage using your storage account and account key.
How do I backup my SQL Server database to Azure Blob storage? ›
- Open the Azure portal.
- Navigate to your Storage Account.
- Select the storage account, scroll down to Blob Services.
- Select Blobs and then select + Container to add a new container.
- Enter the name for the container and make note of the container name you specified. ...
- Select OK.
The data movement can be of the following types: Offline transfer using shippable devices - Use physical shippable devices when you want to do offline one-time bulk data transfer.
Is data transfer from Azure to on-premise free? ›Data Egress Considerations
All inbound or ingress data transfers to Azure data centers from on-premises environments are free. However, outbound data transfers (except in few cases like backup recovery) incur charges.
- In the Azure portal, navigate to your storage account.
- Under Settings, select SFTP. Note. This option appears only if the hierarchical namespace feature of the account has been enabled. ...
- Select Enable SFTP. Note. If no local users appear in the SFTP configuration page, you'll need to add at least one of them.
Create an Azure Database Migration Service instance
In the Azure portal menu or on the Home page, select Create a resource. Search for and select Azure Database Migration Service. On the Azure Database Migration Service screen, select Create. Select the option Continue to use Azure Database Migration Service.
- Go to the Azure portal to find your database in SQL Database. ...
- Select the database you want to use as the hub database for Data Sync. ...
- On the SQL database menu for the selected database, select Sync to other databases.
- On the Sync to other databases page, select New Sync Group.
Connect and query a SQL Server instance on an Azure VM using SQL Server Management Studio (SSMS) - SQL Server Management Studio (SSMS) Connect to a SQL Server instance on an Azure VM using SSMS. Create and query SQL Server on an Azure VM by running basic T-SQL queries in SSMS.
What is the simplest method to migrate a database? ›Using AWS DMS to migrate data to AWS is simple. You start by spinning replication instances in your AWS environment, and then AWS DMS connects the source and target database endpoints. You can choose what you want to migrate—DMS allows you to migrate tables, schemas, and whole databases.
Which tool is best for data migration? ›- Data Migration Tools: Hevo Data.
- Data Migration Tools: Fivetran.
- Data Migration Tools: Matillion.
- Data Migration Tools: Stitch Data.
- Data Migration Tools: AWS Data Pipeline.
- Data Migration Tools: Integrate.io.
- Data Migration Tools: IBM Informix.
- Data Migration Tools: Azure DocumentDB.
- On your current SQL Server, open Microsoft SQL Server Management Studio with an account which has admin rights on SQL Server.
- Select UserLock Database, make a right click to display the context menu, select Tasks then click on Detach.
How to sync data from one database to another in SQL Server? ›
Right-click the "Databases" folder in Object Explorer, and click "Synchronize" from the drop-down menu. The Synchronize wizard appears.
What is the key benefit of using Azure SQL Database compared to using SQL Server on-premises? ›Azure SQL allows you to benefit from almost unlimited cloud scalability and has high availability out of the box. If you also need full control over the operating system or compatibility with on-premises workloads such as SQL Server Reporting Services you can run SQL Server on an Azure VM.
How do I connect to Azure SQL database using ODBC? ›In Windows, search for ODBC Data Sources, and open the ODBC Data Sources desktop app. Select Add. Select ODBC Driver 17 for SQL Server then Finish. Enter a name and description for the connection and the cluster you want to connect to, then select Next.
Which account can always connect to Azure SQL Database? ›When you create an Azure SQL database, which account can always connect to the database? When you first deploy Azure SQL, you specify an admin login and an associated password for that login. This administrative account is called Server admin.
How do I connect my premise database to Azure? ›Unfortunately, you cannot directly connect on-premise database to Azure Synapse notebooks. The best way to work with this is to pull the data into Azure Data Lake store, and then run your notebook on the storage account and then write it back to your on-prem servers.