How to Perform Data Migration in SQL
When managing files and databases, developers often use the main database server to store them. As such, the stored data may be victim to data loss, theft, and corruption, affecting the individual, the company, and the clients.
That's where data migration involves moving files and data from one server to another. It is common in SQL servers such as Microsoft SQL servers, and one can move data to another SQL, NoSQL, or Azure server. Here are more details about the types of SQL data migration and how you can achieve it using the mentioned servers.
What is data migration in SQL?
Data migration means moving digital information to a different location, file format, environment, storage system, database, data center, or application that fits the definition of data migration.
SQL data migration transfers data and files from one SQL server to another. Despite how easy it sounds, the migration process is a bit complex, especially when dealing with large corporate data. As a result, many companies prefer using data migration tools to make the process fast and efficient.
Regarding the ETL (Extract, Transform, Load) process, the data migration process involves:
Pulling data from one application.
Transforming it.
Loading it to the destined server.
What are the types of SQL data migration?
There are different types of SQL data migration, each with its challenges:
Database migration: This type of data migration involves moving multiple databases from one server to another. Backing up the database is crucial before performing data migration.
Storage migration: The user transfers data and files from one storage device to another, transferring storage blocks and files from a storage system to a disk, tape, or cloud.
Application migration: The data migration moves applications or programs from one server to another. Due to its complexity, using a middleware to bridge technology gaps during the migration is recommended.
Cloud migration: It is the process of moving data and files from a physical server to a cloud server or from one cloud server to another.
Business process migration: Mostly used by large enterprises, this type of migration moves business data such as customer, product, and operational data and processes to a new server environment.
What is the purpose of SQL data migration?
The circumstances that may require users to move or retrieve databases include the following:
File and application backup
Access to data from multiple servers
Making a move to a new server or cloud server.
Transferring to a different instance of SQL.
Creating a development server.
Restoring a database from backup.
What are the important concepts of SQL data migration?
The important concepts of SQL data migration are as follows:
Data extraction: Involves pulling data from the source database or server and sending it to a staging or intermediary server.
Data standardization: Matching the source data to the destination formats could cater to compatibility issues with the data type or ensure that metadata correctly reflects the data.
Data Transformation: The process of modifying the data value, type, or structure from the source database to a suitable format for the target database.
Data aggregation and cleansing: Perform aggregation tasks to de-duplicate records or calculate derived fields.
Data loading: Transferring the cleansed, aggregated, and transformed data into the destination database.
What are the SQL tools used in data migration?
Since SQL data migration can be complex, tools are used to move or modify data as needed. Some developers may develop their data migration tools from scratch, which is beneficial as they can tailor the tools according to their specific systems or uses. However, developing one from scratch is time-consuming, runs into challenging scaling, and is expensive.
That's why most developer teams opt for existing data migration tools to make the process simpler, faster, and more efficient. Examples of these SQL data migration tools include:
SQL Server Migration Assistant (SSMA)
Database Experimentation Assistant (DEA)
Data Migration Assistant (DMA)
Azure Database Migration Service (DMS)
Azure Migrate
Azure SQL migration extension for Azure Data Studio
Below is a deeper insight into the above-mentioned migration tools to speed up the migration process in SQL;
i. SQL Server Migration Assistant (SSMA)
SSMA is the most common data migration tool to move databases between SQL servers or Azure SQL Servers. The data migration tool automates database migration to SQL Server and Azure SQL from alternative database engines. Situations required to use the SSMA include:
- Migrating MySQL, Microsoft Access, and Oracle databases to SQL Server.
Migrating MySQL, Microsoft Access, and Oracle databases to Azure SQL.
ii. Database Experimentation Assistant (DEA)
The DEA data migration tool is mostly used with SQL Server upgrades since it can elevate a specified SQL version for a specific workload. It is used in the following situations:
- Identifying and evaluating the workload of a source SQL Server environment to prepare for migration.
Identifying compatibility errors and possible degraded queries for an SQL Server migration.
iii. Data Migration Assistant (DMA)
The Data Migration Assistant is used to upgrade the current database server to a modern data platform. The process involves detecting compatibility issues that can affect the database functionality in the updated version of SQL Server or Azure SQL Database. Thus, the DMA recommends performance and reliability improvements for the target environment and moves the database's schema, data, and uncontained objects from the source server to the target server.
It is mostly used to:
Upgrade SQL Servers to the latest version.
Migrate the schema, data, and uncontained objects from a source server to SQL Server or Azure SQL.
Detect compatibility issues that can alter database functionality on a newer target version of SQL Server or Azure SQL.
iv. Azure Database Migration Service (DMS)
The Azure DMS performs seamless migrations across multiple tables from SQL data sources to Azure Data platforms in minimal time. Additionally, it provides a resilient and reliable migration pipeline with minimal user involvement during the migration process. It is often used to migrate SQL databases to Azure databases on a large scale.
v. Azure Migrate
Azure Migrate is a type of SQL data migration tool that provides a central hub for discovering and assessing on-premises servers, infrastructure, applications, and data to an Azure database at a large scale. As a result, it offers a synchronous migration across your databases, servers, and applications.
Azure Migrate is used to:
Access and discover an SQL server data infrastructure.
Obtain Azure SQL deployment recommendations, target sizing, and monthly estimates.
Lift your entire data infrastructure to SQL Server on Azure virtual machines.
vi. Azure SQL migration extension for Azure Data Studio
It is a powerful tool that simplifies the database migration from the SQL Server to the Azure SQL Server. The extension's design aims to work with Azure Data Studio and Azure SQL, among other data platforms. The purpose of the Azure SQL migration extension is to provide an efficient user interface to guide users through the migration process, with several options for customization and optimization.
Instances that require one to work with the Azure SQL migration extension for Azure Data Studio include:
Migrating small or large databases.
Migrating SQL Server databases to Azure Server databases without using complex scripts or manual steps.
How to migrate data from an SQL server
Now that we have covered the importance of database migration and the tools used to achieve the process, a choice is made on the source and target servers that perform the data migration. Using an SQL server as the source server, here is how to migrate databases to:
i. To another SQL server
Below are the steps on how to migrate databases and schemas from one SQL server to another SQL server using Database Migration Assistant:
Select "New" and then "Migrate" on the left panel of the SQL Server main page.
Choose SQL Server as the source and target database server type if you are upgrading an on-premises SQL Server to a later version, then select "Create."
Next, add the SQL Server name in the Server name field in both the Source and Target server details section, respectively.
Choose the Authentication type supported by the source and target SQL Server instance. To encrypt the connection, select Encrypt connection in the Connection properties section and click on Next.
Select the specific databases to be migrated on the "Add databases" page. All the databases on the source SQL Database Server are selected for migration by default.
Go to the "Share location" options box to add a shared location to which the source and target SQL Server instances have access.
When there is no shared location to which the source and target SQL Servers are granted access, select the "Copy the database backups to a different location from which the target server can read and restore" option. Next, enter a value for the "Location for backups for the restore option" box.
Ensure that the user account with the DMA has read privileges to the backup location and writes privileges to the location from which the target server restores, and then select "Next".
Select the specific logins for migration and ensure that the logins are mapped to one or more authorized users in the databases selected for migration. All the SQL Server and Windows logins qualifying for migration are selected by default.
Select "Start Migration" to begin the migration process. You can monitor the migration progress on the "View Results" page.
Click on the "Export report" option below the View results page to save the migration results into a CSV file format.
Review the saved file concerning the login migration details, then verify the changes.
ii. To Azure SQL database
Before performing database migration between the two servers, ensure that the prerequisites below have been followed:
Choose the required migration method and corresponding tools.
Install the Azure SQL migration extension for Azure Data Studio.
Create a target Azure SQL Database.
Configure connectivity and proper permissions to access both source and target.
Review the database engine features available in Azure SQL Database.
Below is a procedural guide on how to migrate databases from an SQL server to an Azure SQL Database using the Azure SQL migration extension for Azure Data Studio:
Download and install Azure Data Studio along with the Azure SQL migration extension.
Open the 'Migrate to Azure SQL Migration wizard' within the Azure Data Studio extension.
Choose the databases for assessment to review migration readiness and identify any potential issues.
Connect to your Azure account and select the target Azure SQL Database within your subscription.
Specify the tables you intend to migrate.
Use the Azure Data Studio wizard to create a new Azure Database Migration Service. Should you have an existing one created through Azure Data Studio, you can reuse it.
If your backups are stored on an on-premises network share, download and install the self-hosted integration runtime on a machine capable of connecting to the source SQL Server and accessing the backup location.
Commence the database migration process and monitor its progress within Azure Data Studio. Monitoring progress is also possible through the Azure Database Migration Service resource in the Azure portal.
When you are done migrating the database, go through the post-migration tasks, which include performing tests and updating statistics, to ensure everything functions smoothly and efficiently.
Best practices for a successful data migration in SQL Server and Azure SQL Database
Having completed and successfully migrated all the databases from the source to the target server, here are some tips you should adhere to to ensure a successful transaction, minimize risks, and optimize performance.
Do not install and run the DMA tool directly on the SQL Server host machine. Instead, install the DMA on a separate machine or Azure virtual machine.
Migrate a server during non-peak times when it is least in service.
When migrating a database, enter one shared location accessible by the source and target servers. Additionally, ensure you provide the correct permissions specified in the tool to the shared folder to avoid migration failures.
Activate the encrypted connection when connecting the source and target servers. You can use TLS encryption to increase the security of data transmitted across the networks between DMA and the SQL Server.
After completing the migration, inspect the target database again and check for any constraints that became untrusted during the data movement.
Conclusion
SQL data migration is a crucial and complex process that demands meticulous planning and execution. Organizations can seamlessly transition their data while minimizing downtime and ensuring data integrity by leveraging data migration tools like the Data Migration Assistant and employing best practices. Prioritizing comprehensive backups, strategic testing, and using a phased approach are also important for successful data migration, ensuring a smooth transition without compromising the integrity or accessibility of the data.
Resource Links
Subscribe to my newsletter
Read articles from Stephanie Beatrice directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by