This article is contributed. See the original author and article here.

Introduction


Did you know that you can use Microsoft Fabric to copy data at scale from on-premises SQL Server to Azure SQL Database or Azure SQL Managed Instance within minutes?


 


It is often required to copy data from on-premises to Azure SQL database, Azure SQL Managed Instance or to any other data store for data analytics purposes. You may simply want to migrate data from on-premises data sources to Azure Database Services. You will most likely want to be able to do this data movement at scale, with minimal coding and complexity and require an automated and simple approach to handle such scenarios.


 


In the following example, I am copying 2 tables from an On-premises SQL Server 2019 database to Azure SQL Database using Microsoft Fabric. The entire migration is driven through a metadata table approach, so the copy pipeline is simple and easy to deploy. We have used this approach to copy hundreds of tables from one database to another efficiently. The monitoring UI provides flexibility and convenience to track the progress and rerun the data migration in case of any failures. The entire migration is driven using a database table that holds the information about the tables to copy from the source.  


 


Architecture diagram


This architectural diagram shows the components of the solution from SQL Server on-premises to Microsoft Fabric.


addy_0-1687194528376.png


 


Steps


Install data gateway:


To connect to an on-premises data source from Microsoft Fabric, a data gateway needs to be installed. Use this link to install an on-premises data gateway | Microsoft Learn


 


Create a table to hold metadata information:


First, let us create this table in the target Azure SQL Database.


 


 


 


 

CREATE TABLE [dbo].[Metadata](
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [DataSet] [nvarchar](255) NULL,
      [SourceSchemaName] [nvarchar](255) NULL,
      [SourceTableName] [nvarchar](255) NULL,
      [TargetSchemaName] [nvarchar](255) NULL,
      [TargetTableName] [nvarchar](255) NULL,
      [IsEnabled] [bit] NULL 
)

 


 


 


 


 


 


I intend to copy two tables – Customer and Sales – from the source to the target. Let us insert these entries into the metadata table. Insert one row per table.


 


 


 


 

INSERT [dbo].[Metadata] ([DataSet], [SourceSchemaName], [SourceTableName], [TargetSchemaName], [TargetTableName], [IsEnabled]) VALUES (N'Customer', N'dbo', N'Customer', N'dbo', N'Customer', 1);

INSERT [dbo].[Metadata] ([DataSet], [SourceSchemaName], [SourceTableName], [TargetSchemaName], [TargetTableName], [IsEnabled]) VALUES (N'Sales', N'dbo', N'Sales', N'dbo', N'Sales', 1);

 


 


 


 


 


 


Ensure that the table is populated. The data pipelines will use this table to drive the migration.


addy_1-1687194528380.png


 


Create Data Pipelines:


Open Microsoft Fabric and click create button to see the items you can create with Microsoft Fabric.


addy_0-1687203365811.png


 


Click on “Data pipeline” to start creating a new data pipeline.


addy_2-1687194559507.png


 


Let us name the pipeline “Copy_Multiple_Tables”.


addy_3-1687194559511.png


 


Click on “Add pipeline activity” to add a new activity.


addy_4-1687194559514.png


 


Choose Azure SQL Database from the list. We will create the table to hold metadata in the target.


addy_5-1687194559516.png


 


Ensure that the settings are as shown in the screenshot.


addy_6-1687194559518.png


 


Click the preview data button and check if you can view the data from the table.


addy_7-1687194559518.png


 


Let us now create a new connection to the source. From the list of available connections, choose SQL Server, as we intend to copy data from SQL Server 2019 on-premises. Ensure that the gateway cluster and connection are already configured and available. 


addy_8-1687194559524.png


 


Add a new activity and set the batch count to copy tables in parallel.


addy_9-1687194559528.png


 


We now need to set the Items property, which is dynamically populated at runtime. To set this click on this button as shown in the screenshot and set the value as:


 


 


 


 

@activity('Get_Table_List').output.value

 


 


 


 


 


addy_10-1687194559530.png


 


addy_11-1687194559534.png


 


Add a copy activity to the activity container.


addy_12-1687194559536.png


 


Set the source Table attributes in the copy activity as shown in the screenshot. Click on the edit button and click the “Add dynamic content” button. Ensure that you paste the text only after you click the “Add dynamic content” button, otherwise, the text will not render dynamically during runtime.


 


Set the Table schema name to:


 


 


 


 

@item().SourceSchemaName

 


 


 


 


 


 


 


Set the Table name to:


 


 


 


 

@item().SourceTableName

 


 


 


 


 


addy_13-1687194559541.png


 


Click on the destination tab and set the destination attributes as in the screenshot.


Set the Table schema name to:


 


 


 


 

@item().TargetSchemaName

 


 


 


 


 


Set the Table name to:


 


 


 


 

 @item().TargetTableName

 


 


 


 


 


addy_14-1687194559547.png


 


We have configured the pipeline. Now click on save to publish the pipeline.


addy_15-1687194559551.png


 


Run pipeline:


Click the Run button from the top menu to execute the pipeline. Ensure the pipeline runs successfully. This will copy both tables from source to target.


addy_16-1687194559556.png


 


Summary:


In the above example, we have used Microsoft Fabric pipelines to copy data from an on-premises SQL Server 2019 database to Azure SQL Database. You can modify the sink/destination in this pipeline to copy to other sources such as Azure SQL Managed Instance or Azure Database for PostgreSQL. If you are interested in copying data from a mainframe z/OS database, then you will find this blog post from our team also very helpful.


 


Feedback and suggestions 


If you have feedback or suggestions for improving this data migration asset, please contact the Azure Databases SQL Customer Success Engineering Team. Thanks for your support!


 


Note: For additional information about migrating various source databases to Azure, see the Azure Database Migration Guide.


 

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.