Database Ingestion and Replication > Sources - preparation and usage > Microsoft SQL Server, RDS for SQL Server, Azure SQL Database, and Azure Managed Instance sources
  

Microsoft SQL Server, RDS for SQL Server, Azure SQL Database, and Azure Managed Instance sources

To use Microsoft SQL Server sources in database ingestion and replication tasks, first prepare the source database and review the usage considerations. SQL Server source types include on-premises SQL Server, Relational Database Service (RDS) for SQL Server, Azure SQL Database, and Azure SQL Managed Instance.

Source preparation

Usage considerations

SQL Server permissions

You must grant some SQL Server permissions to the database ingestion and replication user for a SQL Server source.

Prerequisite for SQL Server CDC enablement

You must enable SQL Server CDC on the database and on the source tables for incremental load and combined load jobs that use the Log-based or CDC Tables capture method to be able to capture changes.
To enable CDC on the database:
To enable CDC on SQL Server source tables, ensure you have the db_owner role and run the following command:
EXEC sys.sp_cdc_enable_table @source_schema = N'<schemaname>', @source_name = N'<tablename>', @role_name = NULL;
Note:
The syntax for sp_cdc_enable_table includes the minimum required arguments. More arguments are available. For more information, see the SQL Server documentation.

Permissions required to replicate data

The permissions required depend on the job's load type and CDC method.
User creation
The database connection needs a login user created in both the master database and source database.
USE master;
CREATE DATABASE <DB>;
CREATE LOGIN <login_name> WITH PASSWORD = '<password>';
CREATE USER <user> FOR LOGIN <login_name>;

USE <DB>;
CREATE USER <user> FOR LOGIN <login_name>;
Permissions for initial load jobs
For initial load jobs, the following minimum permissions are required:
GRANT SELECT ON <table> TO <user>;
GRANT SELECT ON sys.system_internals_partition_columns to <user>;
Permissions for incremental load and combined initial and incremental load jobs
For incremental load and combined load jobs, you need the minimum permissions shown above for initial load jobs plus some additional permissions required for incremental CDC processing. The CDC permissions depend on the CDC method you use.

Change capture mechanisms for SQL Server sources

Database Ingestion and Replication provides multiple change capture mechanisms for capturing change data from a SQL Server source and applying the data to a target.

Change capture with CDC tables only

Database ingestion and replication incremental load jobs can capture changes directly from the SQL Server CDC tables without using the transaction log. CDC Tables is the default CDC method.
The following components are involved in the change capture processing that uses CDC tables only:
The following image shows the SQL Server log-based change data capture components and data flow:
  1. 1The CDC Capture-Instance Table Reader reads changes from a cdc. <capture instance>_CT table.
  2. 2The CDC Capture-Instance Table Reader sends change records to the CDC Writer.
  3. 3The CDC Writer formats the change records and applies them to the target.

Log-based change data capture with transaction log and CDC tables

Database ingestion and replication incremental load jobs that use log-based CDC capture DML and DDL changes by parsing records from the active transaction log and by reading change records directly from the CDC tables. Change data is read from the active transaction log if the required restart point (LSN) is available there. If the capture start point pre-dates records in the transaction log or in certain other situations, Database Ingestion and Replication automatically transitions to reading change data from the CDC tables. After reading changes from the CDC tables, Database Ingestion and Replication switches back to reading changes from the active transaction log in a transparent manner.
The following components are involved in log-based change capture processing:
The following image shows the SQL Server log-based change data capture components and data flow:
  1. 1The Log Reader process reads log records to capture DML and DDL changes in committed transactions.
  2. Capture processing continues until the committed transactions are complete, the capture process is stopped or interrupted by a fatal error, or a switch to reading change records from a cdc.<capture_instance>_CT table is triggered.
  3. 2In certain situations, Database Ingestion and Replication automatically switches to reading changes from a cdc. <capture instance>_CT table by using the CDC Capture-Instance Table Reader.
  4. Processing switches to the cdc.<capture instance>_CT table under the following conditions:
  5. 3The Log Reader and CDC Capture-Instance Table Reader send change records to the CDC Writer.
  6. 4The CDC Writer formats the change records and applies them to the target.

Query-based change capture

Database ingestion and replication jobs capture insert and update changes in the source by querying a timestamp column that is updated when a change occurs. Configuration of the source is limited to adding the common CDC query column to each source table. The query-based CDC method uses the query column to identify the rows that changed since the beginning of a specified CDC interval.
To implement the query-based change capture, set the following options on the Source page of the task wizard:
After the CDC interval elapses, Database Ingestion and Replication uses a SQL query with a WHERE clause that references the CDC query column to identify the rows that received changes during the CDC interval. The change data is captured and applied to the target.
If the source tables selected for the query-based CDC do not have the CDC query column, change data capture will ignore these tables and will continue with the rest of the tables. For the tables that are skipped, corresponding tables generated in the target database will be empty. If none of the source tables have a CDC query column, the job will fail at runtime.
The following image shows the SQL Server query-based change data capture components and data flow:
  1. 1After the CDC interval elapses, Database Ingestion and Replication executes a SQL query in the source database that uses the CDC query column to extract the change data.
  2. 2Change records are sent to the CDC Writer.
  3. 3The CDC Writer formats the change records and applies them to the target.