INSERT, UPDATE, and DELETE operations committed to the tables for which change data capture is enabled, once it’s deployed. The connector can then record and broadcast these events.
Video example
Expand this box to watch our video about configuring Microsoft SQL Server for a .Prerequisites
Before the can be used to load data from Microsoft SQL Server, the database must be configured. To perform these steps, the following is required:- A
sysadminuser must enable change data capture for the Microsoft SQL Server database (or Azure SQL Managed Instance).- In an Azure SQL Database, the
db_ownerrole is required to enable change data capture.
- In an Azure SQL Database, the
- The Microsoft SQL Server agent must be running.
Enabling change data capture on the database
As noted in Prerequisites, a privileged user must first enable change data capture on the database before a capture instance for specific tables can be established.-
To determine if a database already has change data capture enabled, run the following command:
If the value for
is_cdc_enabledis1, then change data capture is enabled for the database. Otherwise, it’s not enabled. -
To enable change data capture on your database, run the following stored procedure:
Enabling the database for change data capture will trigger the creation of several database-specific resources: a schema with the name
cdc, a change data capture user, metadata tables, and other system objects.
Creating a change data capture user role
-
Create a Microsoft SQL Server user to be used by the Microsoft SQL Server Reader. The user should have
sysadmin, a fixed server role, and must use the Microsoft SQL Server authentication mode, which must be enabled in Microsoft SQL Server. -
Grant the Microsoft SQL Server Reader user the
db_ownerrole. This must be done for each database that you want to read. Use the following commands, substituting your own details: -
For example, to enable change data capture on the database
mydb, create a userstreaming_user, and give that user thedb_ownerrole onmydb:
Enabling change data capture on a table
Once your database has been enabled for change data capture, you must then enable it for all tables that you wish to capture data from. A capture instance for each source table must be created. To do so, the creating member must have thedb_owner fixed database role. The stored procedure sys.sp_cdc_enable_table can then be used as described below.
-
Use the following command to retrieve all the source tables that have been enabled for change data capture:
-
Use the following command to enable change data capture on source tables you want to capture:
| Field name | Description |
|---|---|
| @source_name | Specifies the name of the table that you want to capture. |
| @role_name | Specifies a role you can add users to, who you want to grant SELECT permission on the captured columns of the source table. sysadmin or db_owner roles also have access to the specified change tables. Set the value of @role_name to NULL, to allow only members in the sysadmin or db_owner roles to have full access to captured information. |
| @filegroup_name | Specifies the filegroup where SQL Server places the change table for the captured table. The named filegroup must already exist. It’s best not to locate change tables in the same filegroup that you use for source tables. |
| @supports_net_changes | For more information, read Microsoft @supports_net_changes. |
When
@supports_net_changes is set to 1, an additional non-clustered index is created on the change table, and the net changes query function is created. Because this index needs to be maintained, enabling net changes can have a negative effect on streaming performance.Verify user access to the streaming table
To retrieve change data capture configuration information from a database or table, a Microsoft SQL Server administrator can use a system stored procedure. This type of administrator with the necessary privileges must do the following:- Make sure all the captured columns in the change data capture instance have
SELECTpermissions. Members of thedb_ownerdatabase role have access to all the defined capture instances’ information. - Have membership in any gating roles that are defined for the table information that the query includes.
- Run the
sys.sp_cdc_help_change_data_capturestored procedure to query the table.
sys.sp_cdc_help_change_data_capture on the database MyDB to query a table for change data capture configuration information:
Microsoft SQL Server always on
The Microsoft SQL Server connector can capture changes from an Always On read-only replica.Prerequisites
- Change data capture is configured and enabled on the primary node. Microsoft SQL Server doesn’t support streaming directly on replicas.
- The read-only replica must be configured with Readable Secondary as either
Read-intent onlyorYes. For more information, read Microsoft’s documentation, including the detailed steps in the article. - Ensure the Read Replica toggle is on when creating your pipeline.
Schema drift
Schema drift occurs when your data source changes its metadata, by adding, removing, or changing fields, columns, and types. When not handled correctly, schema drift will cause a difference between the data source, and your streaming pipeline configuration, resulting in the pipeline failing or processing incorrect information. Due to Microsoft SQL Server limitations, can’t automatically handle schema drift on source tables in Microsoft SQL Server databases. A Microsoft SQL Server connector with change data capture enabled does not automatically propagate any schema changes, such as existing column data type or size changes, renamed columns, new tables, or new columns, meaning you may have to reconfigure your pipeline in response to changes in the source metadata. To accommodate offline or online schema updates, follow the steps outlined in the following Debezium links to ensure that the changes will be reflected in your streaming pipeline:Limitations
- To build a change data capture instance in Microsoft SQL Server, the base object must be a table. As a result, Microsoft SQL Server doesn’t enable collecting changes from indexed views (also known as materialized views).
- If the Microsoft SQL Server agent service isn’t running, Microsoft SQL Server change data capture jobs won’t execute.
- Streaming doesn’t support the values for computed columns even if the computed column is defined as persisted. Computed columns that are included in a capture instance always have a value of NULL.
Large object (LOB) data types
When streaming tables that include large object (LOB) or unstructured data types, pipelines can fail if the data exceeds server configuration limits. Failures may include errors indicating incomplete responses from the database, for example:max text repl size limit, the result set can be truncated, which may cause incomplete data to be returned. This is a common cause of failures when LOB columns are present.
To check the current setting, run:

