How to merge Azure SQL Databases ?

Cezar Lupu 0 Reputation points
2024-06-05T12:23:34.3133333+00:00

Hello everyone,

What would be the easiest/simplest way to migrate data(tables, data) from 6 azure databases to a new azure databases (no duplicate tables) All databases are on the same subscription, resource group, sql server. Short summary I want to merge 6 databases into one.

Thank you

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Morillo 34,671 Reputation points MVP Volunteer Moderator
    2024-06-05T13:42:59.7+00:00

    Azure SQL Data Sync can do the job in this scenario. Create the empty tables using scripts on the central (hub) database and configure Azure SQL Data Sync to do the job. It will copy the tables using BULK INSERTS. Scale up the service tier of the databases involved when syncing.

    You can also use Azure Data Factory to copy the tables between databases. You can copy the table in BULK as explained on this video. See this documentation for more information.

    For small tables you may find easy to script the data and schema as explained here.

    You can also use elastic queries on the central database (hub database) to retrieve data from the tables on the other databases. Below a simplified example:

    CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<password>';
    
    CREATE DATABASE SCOPED CREDENTIAL SQL_Credential  
    WITH IDENTITY = '<username>',
    SECRET = '<password>';
    
    CREATE EXTERNAL DATA SOURCE RemoteReferenceData
    WITH
    (
        TYPE=RDBMS,
        LOCATION='<server>.database.windows.net',
        DATABASE_NAME='<db>',
        CREDENTIAL= SQL_Credential
    );
    
    CREATE EXTERNAL TABLE [dbo].[source_table] (
        [Id] BIGINT NOT NULL,
        ...
    )
    WITH
    (
        DATA_SOURCE = RemoteReferenceData
    )
    
    SELECT *
     INTO target_table
    FROM source_table
    
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.