跳到主要内容

SQL Server Database Migration: 5 Methods and 7 Steps

· 阅读需 11 分钟
Kristen
Kristen

A SQL Server database migration moves schemas, data, and supporting objects to a new SQL Server, Azure SQL, PostgreSQL, or another platform.

Use native backup and restore for a SQL Server-to-SQL Server move with an acceptable maintenance window. For a different database engine, convert the schema first. To minimize downtime, combine a full load with change data capture (CDC), then pause writes briefly for validation and cutover.

SQL Server Database Migration at a Glance

Choose the migration method based on the destination and the maximum acceptable downtime:

Migration scenarioRecommended starting pointTypical downtimeMain consideration
Move a SQL Server database to a new serverNative backup and restorePlanned maintenance windowSimple and reliable for homogeneous moves
Copy a small database between SQL Server instancesCopy Database WizardUsually offline or maintenance-window basedConvenient, but less controllable for complex production moves
Migrate selected tables or transform dataSSIS or Import and Export WizardDepends on workflowFlexible, but not a complete instance migration
Migrate SQL Server to AzureAzure migration tooling or native restore, depending on targetOffline or online, depending on the supported pathTarget compatibility varies across Azure SQL options
Migrate SQL Server to PostgreSQL or another engineSchema conversion plus full load and CDCDepends on load and cutover designData types, SQL syntax, and application behavior must be remediated
Keep a busy production database online during migrationFull load plus change data capture (CDC)Short final write pauseRequires change replication, validation, and controlled switchover

What Does a SQL Server Migration Include?

A complete inventory should include:

  • Tables, indexes, constraints, views, and stored procedures;
  • Users, roles, permissions, and server logins;
  • SQL Server Agent jobs and maintenance plans;
  • Linked servers, credentials, proxies, and Database Mail settings;
  • SQL Server Integration Services (SSIS) packages;
  • Change Data Capture, replication, Service Broker, or CLR dependencies;
  • Encryption certificates and keys;
  • Application connection strings and DNS records;
  • Monitoring, backups, auditing, and disaster-recovery configuration.

Without these dependencies, a successfully restored database may still be unusable.

5 SQL Server Database Migration Methods

1. Native Backup and Restore

Backup and restore is the standard way to move an entire database between SQL Server instances. Differential and transaction log backups can shorten the final outage.

Microsoft documents backup and restore as one of the primary ways to copy a database to another server. If the destination uses different file paths, inspect the logical file names and restore with MOVE.

RESTORE FILELISTONLY
FROM DISK = 'D:\Migration\SalesDB.bak';

RESTORE DATABASE SalesDB
FROM DISK = 'D:\Migration\SalesDB.bak'
WITH
MOVE 'SalesDB_Data' TO 'E:\SQLData\SalesDB.mdf',
MOVE 'SalesDB_Log' TO 'F:\SQLLogs\SalesDB_log.ldf',
RECOVERY,
STATS = 10;

Logical file names vary, so inspect the backup and check destination capacity and file collisions before restoring to a new location.

Best for: SQL Server-to-SQL Server migration, hardware refreshes, instance consolidation, and version upgrades with an acceptable maintenance window.

Limitations: It does not migrate every instance-level object, and newer-version backups cannot be restored to older SQL Server versions. Large databases may exceed the outage window.

2. Copy Database Wizard

The Copy Database Wizard in SQL Server Management Studio provides a guided way to copy or move databases between instances.

Best for: Small or moderate SQL Server-to-SQL Server moves where both instances are reachable and the migration is not highly customized.

Limitations: It offers less control for large, highly available, or repeatable production migrations. The Import and Export Wizard is different: it mainly copies tables, views, or query results.

3. SSIS, BACPAC, or Custom ETL

Use SSIS, the Import and Export Wizard, BACPAC, or custom ETL when moving selected data or applying transformations.

Best for: Selective migrations, data consolidation, one-time transformations, and relatively small databases.

Limitations: They may not preserve all objects or transactional relationships. Plan for restartability, deletes, consistency, recovery, and validation. Timestamp-based incremental queries can miss deletes and unreliable timestamps; they are not equivalent to log-based CDC.

4. Azure Database Migration Options

“Migrate SQL Server to Azure” can refer to three substantially different targets:

  • SQL Server on Azure Virtual Machines offers the highest compatibility and instance-level control.
  • Azure SQL Managed Instance provides managed operation with broad SQL Server compatibility.
  • Azure SQL Database is a database-as-a-service target with more feature and instance-level differences.

Assess the workload before selecting the target. SQL Server Agent jobs, cross-database behavior, CLR assemblies, linked servers, and other features may need different treatment depending on the Azure service. Microsoft's Azure SQL migration guidance covers discovery, assessment, target selection, and migration paths.

Available approaches include Azure Database Migration Service, migration experiences integrated with Microsoft's management tooling, Managed Instance link, Log Replay Service, and native backup restore for eligible destinations. For example, Microsoft lists Azure DMS as a near-zero-downtime option for SQL Server to Azure SQL Managed Instance, while native restore requires some downtime.

Best for: Organizations moving SQL Server workloads into Microsoft Azure.

Limitations: Support depends on the destination, source version, features, networking, scale, and downtime target. Always run a compatibility assessment.

5. Full Load Plus CDC

For low downtime, copy existing data and continuously apply new inserts, updates, and deletes while the source remains online.

The process has five stages:

  1. Prepare or convert the target schema.
  2. Start capturing changes from a consistent position.
  3. Perform the initial full load.
  4. Apply accumulated and ongoing changes to the target.
  5. Stop writes briefly, allow replication lag to reach zero, validate, and switch the application.

SQL Server's native Change Data Capture records inserts, updates, and deletes in change tables. A migration platform can consume those changes and deliver them to the destination as part of a managed full-plus-incremental workflow. For high-traffic systems, it may also be possible to read SQL Server CDC from an Always On readable replica to reduce capture work on the primary, subject to the SQL Server topology and tool support.

Best for: Large production databases, heterogeneous database migration, and workloads that need a short final write pause.

Limitations: CDC reduces downtime but adds coordination. Teams must manage transaction log or CDC retention, schema changes, replication lag, target write conflicts, and the exact cutover sequence.

How to Migrate a SQL Server Database in 7 Steps

Step 1: Define the Target and Success Criteria

Document versions, editions, hosting model, database size, peak transaction rate, bandwidth, maintenance window, RPO, and RTO. Set measurable thresholds for downtime, data loss, validation, performance, and the rollback deadline.

Step 2: Inventory Dependencies and Assess Compatibility

Inventory database objects, logins, permissions, jobs, linked servers, encryption, cross-database queries, hard-coded server names, and integrations. Measure table sizes, large objects, long transactions, change rate, log growth, and throughput.

For SQL Server-to-SQL Server migration, confirm version direction, edition features, database compatibility level, collation, authentication, and operating-system differences. For Azure SQL, run Microsoft's assessment tooling and review rules for the selected service.

A heterogeneous database migration also requires data type and application remediation. For SQL Server-to-PostgreSQL, inspect identity and sequence behavior, SQL Server-specific data types, case sensitivity, T-SQL, stored procedures, and transaction semantics. Schema conversion alone does not prove application compatibility.

Step 3: Choose the Migration and Cutover Method

Choose from the methods above based on compatibility and downtime. Compare SQL Server database migration tools when evaluating Microsoft options, AWS DMS, and BladePipe, or use the broader data migration tools comparison for other sources and targets. Estimate load time with a representative test; source reads, compression, encryption, indexes, and target writes can all be bottlenecks.

Step 4: Prepare the Target and Rehearse

Provision enough compute, storage, IOPS, and log capacity. Configure collation, time zones, encryption, networking, backups, monitoring, and access. Create or convert schemas and review mappings. Deferring nonessential secondary indexes may speed up the load, but test its effect on CDC and queries.

Rehearse with a recent production-sized copy. Record load and synchronization time, test resumability and the application, identify manual work, verify reconciliation, and practice rollback.

Step 5: Transfer the Data and Apply Changes

For an offline migration, stop writes before the final backup or export. For CDC, start from a defined change position, run the full load, and monitor the backlog until the target catches up.

Before using CDC, verify the SQL Server version and edition, permissions, SQL Server Agent availability, and retention settings. The source must retain changes long enough for the target to catch up during the full load and any interruption.

Step 6: Validate and Cut Over

Use a layered data verification process:

Validation layerExamples
StructureTables, columns, data types, defaults, indexes, keys, constraints
VolumeRow counts by table and partition
ContentChecksums, aggregates, null counts, sampled record comparison
Change consistencyInserts, updates, and deletes arrive correctly and in order
ApplicationCritical transactions, reports, APIs, jobs, and integrations
PerformanceQuery latency, throughput, locks, CPU, I/O, and execution plans
SecurityLogins, roles, permissions, encryption, and audit events

For large tables, compare partition-level counts and deterministic hashes. Then:

  1. Freeze unrelated deployments and stop or queue source writes.
  2. Wait for active transactions to finish and the CDC backlog to reach zero.
  3. Run final data and schema checks, then disable source-side jobs that can write data.
  4. Update connection strings, secrets, DNS, or routing.
  5. Restore application traffic gradually and run smoke tests.

Keep the old source read-only. If both databases must accept writes, test bidirectional replication and conflict handling in advance.

Step 7: Monitor the Target and Retire the Source

Monitor database health, application errors, latency, and business metrics. Keep the source protected and read-only during the rollback period. Once stable, test backup and restore, verify jobs, update monitoring and runbooks, remove temporary access, and decommission the source according to policy.

Common SQL Server Migration Problems

Missing Logins and Orphaned Users

Restored database users may lack matching server logins. Transfer logins with the correct identifiers and test effective permissions.

Version and Edition Incompatibility

Newer-version backups cannot be restored to older versions, and edition-specific features may block downgrades. Check before the migration window.

Collation Differences

Collation affects comparison, sorting, case sensitivity, and joins. Database-level collation does not prevent every conflict with instance objects such as tempdb.

Broken External Dependencies

Include linked servers, file paths, certificates, jobs, service accounts, and hard-coded hostnames in the inventory and cutover test.

Transaction Log Growth

Full loads, open transactions, replication, or delayed CDC can prevent log truncation. Monitor log reuse waits, free space, retention, and lag.

Incomplete Validation

Row counts alone do not prove that values, relationships, and application behavior match. Use structural, content, operational, and application tests.

SQL Server Database Migration Checklist

  • Confirm source and target versions, editions, and compatibility.
  • Define downtime, data-loss, performance, and rollback thresholds.
  • Inventory databases, objects, logins, jobs, integrations, and encryption.
  • Measure data volume, change rate, and available throughput.
  • Back up the source and test restore procedures.
  • Run schema and feature assessments.
  • Rehearse the complete migration and cutover.
  • Monitor source load, transaction logs, network, target capacity, and errors.
  • Track full-load progress and CDC lag.
  • Prevent unplanned schema changes.
  • Validate structure, counts, content, and permissions.
  • Confirm the rollback path is still viable before switching traffic.
  • Run application and business-process smoke tests.
  • Verify backups, monitoring, alerts, and scheduled jobs.
  • Restrict the old source to prevent split-brain writes.
  • Decommission temporary resources only after the rollback window closes.

FAQ

How long does a SQL Server database migration take?

Duration depends on data volume, source read speed, network throughput, target write capacity, index creation, and the ongoing change rate. Measure it with a production-sized rehearsal; database size alone is not a reliable estimate.

Does backup and restore migrate SQL Server logins and Agent jobs?

No. A user database backup does not include server logins, SQL Server Agent jobs, linked servers, credentials, or other instance-level configuration. Migrate and validate them separately.

Can SQL Server be migrated to PostgreSQL?

Yes, but schemas, data types, T-SQL, stored procedures, and application behavior may need conversion. For low downtime, combine schema conversion and a full load with SQL Server CDC.

How do you roll back a SQL Server migration?

Keep the source protected and read-only after cutover, define a rollback deadline, and document how traffic will return to it. If the target has accepted writes, plan how those changes will be reconciled before switching back.