Microsoft SQL Server
This connector uses change data capture (CDC) to continuously capture updates in a Microsoft SQL Server database into one or more Estuary collections.
When to use this connector
Estuary offers three main SQL Server capture connectors and their variants (platform-specific versions for managed providers). All three work across self-hosted and cloud-managed deployments.
| Connector | Mechanism | Latency | Read Replica Support | Key Strengths |
|---|---|---|---|---|
| CDC (this connector) | Log-based change capture | Real-time | Yes* | Full audit history, tables without primary keys |
| Change Tracking | Change tracking | Real-time | No | Computed columns, lower storage overhead |
| Batch | Periodic polling | Minutes to hours | Yes | Views, custom queries, minimal setup |
* CDC can capture from a read replica, but the CDC worker must run on the primary instance.
Choose CDC when:
- You need to capture tables without a primary key
- You need complete audit logging with full row history (CT may combine intermediate changes when they occur in rapid succession)
Choose Change Tracking when:
- You need to capture computed columns or computed primary keys (CDC cannot capture these)
- You want lower storage overhead on the source database (CT stores only primary keys, not full row contents)
- Your tables all have primary keys
Choose Batch when:
- Your SQL Server instance doesn't support CDC or Change Tracking
- You need to capture from database views
- You want to execute custom or ad-hoc queries
Supported versions and platforms
This connector will work on both hosted deployments and all major cloud providers. It is designed for databases using any version of SQL Server which has CDC support, and is regularly tested against SQL Server 2017 and up.
Setup instructions are provided for the following platforms:
Prerequisites
To capture change events from SQL Server tables using this connector, you need:
-
For each table to be captured, a primary key should be specified in the database. If a table doesn't have a primary key, you must manually specify a key in the associated Estuary collection definition while creating the capture. See detailed steps.
-
CDC enabled on both the database and the individual tables to be captured.
- Enabling CDC on a source table create a change table in the database, from which the connector reads. You may optionally enable the "Automatic Capture Instance Management" advanced option to have the connector manage these automatically, but this will require additional permissions. See Automatic Capture Instance Management for more details.
-
A user role with:
- The
VIEW DATABASE STATEor (in newer versions of SQL Server)VIEW DATABASE PERFORMANCE STATEpermission. SELECTpermissions on the CDC schema and the schemas that contain tables to be captured.- Access to the change tables created as part of the SQL Server CDC process.
- The
Setup
To meet these requirements, follow the steps for your hosting type.
Self-hosted SQL Server
- Connect to the server and issue the following commands:
USE <database>;
-- Enable CDC for the database.
EXEC sys.sp_cdc_enable_db;
-- Create user and password for use with the connector.
CREATE LOGIN flow_capture WITH PASSWORD = 'secret';
CREATE USER flow_capture FOR LOGIN flow_capture;
-- Grant the user permissions on the CDC schema and schemas with data.
-- This assumes all tables to be captured are in the default schema, `dbo`.
-- Add similar queries for any other schemas that contain tables you want to capture.
GRANT SELECT ON SCHEMA :: dbo TO flow_capture;
GRANT SELECT ON SCHEMA :: cdc TO flow_capture;
-- Grant the 'VIEW DATABASE STATE' permission.
GRANT VIEW DATABASE STATE TO flow_capture;
-- Enable CDC on tables. The below query enables CDC on table 'dbo.foobar',
-- you should add similar query for all other tables you intend to capture.
EXEC sys.sp_cdc_enable_table @source_schema = 'dbo', @source_name = 'foobar', @role_name = 'flow_capture';
-
Allow secure connection to Estuary from your hosting environment. Either:
-
Set up an SSH server for tunneling.
When you fill out the endpoint configuration, include the additional
networkTunnelconfiguration to enable the SSH tunnel. See Connecting to endpoints on secure networks for additional details and a sample. -
Allowlist the Estuary IP addresses in your firewall rules.
-
Azure SQL Database
-
Allow connections between the database and Estuary. There are two ways to do this: by granting direct access to Estuary's IP or by creating an SSH tunnel.
-
To allow direct access:
- Create a new firewall rule that grants access to the Estuary IP addresses.
-
To allow secure connections via SSH tunneling:
- Follow the guide to configure an SSH server for tunneling
- When you configure your connector as described in the configuration section above, including the additional
networkTunnelconfiguration to enable the SSH tunnel. See Connecting to endpoints on secure networks for additional details and a sample.
-
-
In your SQL client, connect to your instance as the default
sqlserveruser and issue the following commands.
USE <database>;
-- Enable CDC for the database.
EXEC sys.sp_cdc_enable_db;
-- Create user and password for use with the connector.
CREATE LOGIN flow_capture WITH PASSWORD = 'secret';
CREATE USER flow_capture FOR LOGIN flow_capture;
-- Grant the user permissions on the CDC schema and schemas with data.
-- This assumes all tables to be captured are in the default schema, `dbo`.
-- Add similar queries for any other schemas that contain tables you want to capture.
GRANT SELECT ON SCHEMA :: dbo TO flow_capture;
GRANT SELECT ON SCHEMA :: cdc TO flow_capture;
-- Grant the 'VIEW DATABASE STATE' permission.
GRANT VIEW DATABASE STATE TO flow_capture;
-- Enable CDC on tables. The below query enables CDC on table 'dbo.foobar',
-- you should add similar query for all other tables you intend to capture.
EXEC sys.sp_cdc_enable_table @source_schema = 'dbo', @source_name = 'foobar', @role_name = 'flow_capture';
-
Note the following important items for configuration:
- Find the instance's host under Server Name. The port is always
1433. Together, you'll use the host:port as theaddressproperty when you configure the connector.
- Find the instance's host under Server Name. The port is always
IAM Authentication
For databases hosted on Amazon RDS, you can authenticate with an AWS IAM role instead of a password. This requires an RDS Proxy in front of the database; see Amazon RDS for SQL Server for setup instructions.
For Azure SQL Database, you can authenticate with an Azure App Registration instead of a password.
Follow the steps in the Azure IAM guide to create an App Registration and make note of the Application ID and Tenant ID to use when configuring the connector's authentication options.
Ensure that the SQL logical server has Entra authentication enabled and connect
to the Azure SQL Database as the Entra admin. This can be done from the
Database Query Editor. Run the following commands to create a user for the App
Registration, granting it the same permissions as the flow_capture user in
the Azure SQL Database setup instructions above:
CREATE USER [my-app-registration-name] FROM EXTERNAL PROVIDER;
GRANT SELECT ON SCHEMA :: dbo TO [my-app-registration-name];
GRANT SELECT ON SCHEMA :: cdc TO [my-app-registration-name];
GRANT VIEW DATABASE STATE TO [my-app-registration-name];
When enabling CDC on tables, use the App Registration name as the gating
role_name argument, or grant the App Registration membership in whichever
gating role your capture instances already use.
Handling DDL Alterations to Source Tables
In SQL Server, adding a column to the source table will not automatically cause it to be added to the CDC change table. Instead Microsoft's recommended approach is to create a second capture instance which reflects the new state of the source table, transition over to the new instance, and then delete the old one.
The connector will automatically detect the existence of a second capture instance and will seamlessly switch over to the newest one as soon as it reaches a point in the event stream where they are both valid. After this switchover occurs you may delete the old instance.
If you are managing capture instances manually, you will need to manually create the new instance with sys.sp_cdc_enable_table, wait for the new column to begin being captured, and then delete the old instance at your leisure using sys.sp_cdc_disable_table.
If you are using Automatic Capture Instance Management, the connector detect DDL alterations to the source table and will handle the whole process of creating a new CDC instance and dropping the old one automatically.
Automatic Capture Instance Management
You may wish to have the connector automatically issue sys.sp_cdc_enable_table (and sometimes also sys.sp_cdc_disable_table) statements on your behalf. This can be done by enabling the option Advanced > Automatic Capture Instance Management and granting the required permission if necessary.
Unfortunately, the sys.sp_cdc_enable_table stored procedure requires membership in the db_owner database role to call.
Granting that permission to the capture user is a hard requirement for using this feature, and can be done by executing ALTER ROLE db_owner ADD MEMBER <user> on the source database.
Automatic Change Table Cleanup
By default, CDC change tables will retain change events for three days. This can be modified via sys.sp_cdc_change_job, but a lower retention period can put you at a higher risk of losing change events in the event of downtime, if the issue persists long enough for unconsumed change events to expire. If this happens a complete backfill will be required to re-establish consistency.
An alternative solution is to enable the option Advanced > Automatic Change Table Cleanup. When this option is enabled, the connector will manually remove change events from the relevant change tables once it receives confirmation that they have been durably persisted into an Estuary collection.
Unfortunately, the sys.sp_cdc_cleanup_change_table stored procedure used to delete CDC events from the change table requires membership in the db_owner database role to call.
Granting that permission to the capture user is a hard requirement for using this feature, and can be done by executing ALTER ROLE db_owner ADD MEMBER <user> on the source database.
Note also that you still need to have enough free storage space to hold the full 3 days of CDC event retention in the worst case. Otherwise, in the event of downtime exceeding what you can store, you have only changed the failure mode to running out of disk space. This option is best used in situations where it is possible to use that much storage but it is still undesirable for other reasons to use that much in normal operation, such as when using flexible storage volumes on a cloud host.
Partitioned Tables
SQL Server can't return the rows of a partitioned table in primary key order without sorting them, unless the table is partitioned on the first column of its primary key. On a large table that sort can take hours.
When a table's primary key index is partitioned on a column other than its first key column, the connector backfills it one partition at a time, in primary key order within each partition. These tables use the Normal backfill mode when the binding's backfill mode is left on automatic. A binding explicitly set to the Precise backfill mode, or whose collection key differs from the table's primary key, is backfilled in primary key order instead, and the connector logs a warning when that backfill starts.
Partitions can be split or merged while a backfill is in progress. If the partition currently being backfilled changes, the connector reads it again from its start. If that partition is merged into the one before it, the connector reads the merged partition again from its start.
Tables whose partition column is computed, or of a floating-point, money, or binary type, are backfilled in primary key order.
This applies to captures created on or after 2026-11-18. Older captures keep backfilling partitioned tables in primary key order unless partition_aware_backfill is added to the capture's feature flags, and adding no_partition_aware_backfill turns it off for newer captures.
Restricting which data the connector reads
To keep specific columns, such as sensitive fields, out of a capture, use redaction rather than database-side column grants. If a value must never leave the source database, capture a table that contains only the permitted columns. See Keeping a column out of a capture.
The rest of this section explains why the database-side controls customers reach for first, such as row-level security and column-level privileges, do not cover the whole capture.
The connector reads data by two different mechanisms, and database-side access controls do not apply to both of them equally:
- Backfill, the initial scan of an existing table, runs an ordinary
SELECT *query against the source table as the capture user. - Replication, the ongoing stream of changes, reads the CDC change tables through
cdc.fn_cdc_get_all_changes_*. The source table is never read on this path.
Any control you apply at the database must account for both.
Row-level security does not restrict replication
Row-level security (RLS) predicates are applied while reading from the base table, so they constrain the backfill. They do not constrain the change events the connector receives through CDC. A policy that hides rows from the capture user during backfill will not stop those same rows from being streamed once replication begins.
Do not rely on RLS alone to keep rows out of a capture. The capture will succeed, and the restricted rows will still arrive through replication.
This is documented SQL Server behavior rather than a connector limitation. Microsoft notes that change data capture "can leak entire rows that should be filtered" to members of the gating role specified when CDC is enabled on a table. See Cross-feature compatibility.
Access to the change tables is granted through that gating role, set by the @role_name argument to sys.sp_cdc_enable_table during setup and configured on the connector as Advanced > CDC Instance Access Role. Any member of that role reads change events unfiltered by RLS.
To restrict rows at the database, separate them before they reach the capture, for example by enabling CDC only on a table that contains the permitted rows.
Column-level privileges are not supported
The backfill query is SELECT *, so the capture user needs SELECT on every captured table at the table or schema level, as shown in the setup instructions:
GRANT SELECT ON SCHEMA :: dbo TO flow_capture;
Denying SELECT on individual columns does not narrow the capture. The backfill requires every column the table defines.
Keeping a column out of a capture
sys.sp_cdc_enable_table accepts a @captured_column_list argument that limits which columns the change table records. This restricts replication only. The backfill still reads every column directly from the source table, so a column list alone does not keep a value out of a capture.
If you narrow a capture instance this way, do not enable Advanced > Automatic Capture Instance Management. When that option is set, the connector creates replacement capture instances itself and does not carry over @captured_column_list, so the excluded columns would begin flowing again.
To remove a sensitive field from a capture, use one of the following:
- Redaction with the
blockstrategy, which removes the value in the Estuary runtime before any document is written to disk. This is the recommended option in most cases. - A database-side table containing only the permitted columns, with CDC enabled on that table and captured in place of the base table. Use this when the value must never leave the source database. CDC cannot be enabled on a view, so a view is not an option here.
Redaction applies only to documents captured after the rule is in place. Ensure any fields you redact are also redacted under _meta/before. See Redacting CDC before-images.
Configuration
You configure connectors either in the Estuary web app, or by directly editing the catalog specification file. See connectors to learn more about using connectors. The values and specification sample below provide configuration details specific to the SQL Server source connector.
Properties
Endpoint
| Property | Title | Description | Type | Required/Default |
|---|---|---|---|---|
/address | Server Address | The host or host:port at which the database can be reached. | string | Required |
/database | Database | Logical database name to capture from. | string | Required |
/user | User | The database user to authenticate as. | string | Required, "flow_capture" |
/historyMode | History Mode | Capture each change event, without merging. | boolean | false |
Authentication
| Property | Title | Description | Type | Required/Default |
|---|---|---|---|---|
/credentials | Authentication | Authentication method and credentials that provide access to the database. | object | Required |
/credentials/auth_type | Auth Type | The authentication method to use. One of UserPassword, AWSIAM, or AzureIAM. | string | |
/credentials/password | Password | Password for the specified database user. | string | Required for UserPassword auth |
/credentials/aws_region | AWS Region | AWS region of your resource. | string | Required for AWSIAM auth |
/credentials/aws_role_arn | AWS Role ARN | AWS role for Estuary to use that has access to the resource. | string | Required for AWSIAM auth |
/credentials/azure_client_id | Azure Client ID | Application (client) ID of the App Registration. | string | Required for AzureIAM auth |
/credentials/azure_tenant_id | Azure Tenant ID | Directory (tenant) ID of the App Registration. | string | Required for AzureIAM auth |
Discovery Filters
Options that restrict which tables are surfaced by discovery. These take effect when discovery runs. If your capture has automatic discovery enabled, a table these filters exclude will be deactivated the next time discovery runs.
| Property | Title | Description | Type | Required/Default |
|---|---|---|---|---|
/discoveryFilters | Discovery Filters | Options that restrict which tables are visible to discovery. | object | |
/discoveryFilters/include_schemas | Include Schemas | If specified, only tables in the listed schemas are discovered. | string array | |
/discoveryFilters/exclude_schemas | Exclude Schemas | Tables in the listed schemas are excluded from discovery. | string array | |
/discoveryFilters/table_patterns | Table Patterns | If specified, only tables matching at least one of these glob patterns are discovered. A pattern containing a . matches against the qualified schema.table name. A pattern without a . matches the unqualified table name in any schema. Use * or ? as wildcards. | string array | |
/discoveryFilters/discover_only_enabled | Discover Only CDC-Enabled Tables | When set, the connector only discovers tables which already have CDC capture instances enabled. Combined as a union with the equivalent setting under Advanced Options. | boolean | |
/discoveryFilters/rules | Discovery Rules | Ordered rules that include or exclude tables or set their destination collections. | array of objects |
Advanced options
| Property | Title | Description | Type | Required/Default |
|---|---|---|---|---|
/advanced | Advanced Options | Options for advanced users. You should not typically need to modify these. | object | |
/advanced/backfill_chunk_size | Backfill Chunk Size | The number of rows which should be fetched from the database in a single backfill query. | integer | 50000 |
/advanced/skip_backfills | Skip Backfills | A comma-separated list of fully-qualified table names which should not be backfilled. | string | |
/advanced/source_tag | Source Tag | This value is added as the property 'tag' in the source metadata of each document. | string | |
/advanced/rediscovery_interval | Rediscovery Interval | How often the connector re-runs discovery while a capture is running, in order to notice schema changes and newly added tables. Accepts duration strings like 15m or 1h, from 1m up to 8760h. | string | "15m" |
/advanced/max_startup_delay | Maximum Startup Delay | How long the connector waits at most before connecting to the database and replicating changes on startup. The actual wait is random between zero and this duration. This is useful when many captures against the same server start at once, because it spreads out the load on the database. Accepts duration strings like 30s, 10m30s, or 2h. No delay when unspecified. | string |
Bindings
| Property | Title | Description | Type | Required/Default |
|---|---|---|---|---|
/namespace | Namespace | The namespace/schema of the table. | string | Required |
/stream | Stream | Table name. | string | Required |
/primary_key | Primary Key Columns | The columns which together form the primary key of the table. | array | |
/mode | Backfill Mode | How the preexisting contents of the table should be backfilled. This should generally not be changed. | string | "" |
/priority | Backfill Priority | Optional priority for this binding. The highest priority binding(s) will be backfilled completely before any others. Negative priorities are allowed and will cause a binding to be backfilled after others. | integer | 0 |
/advanced/additional_backfill_filter | Additional Backfill Filter | Optional filter clause which will be applied to all backfill queries for this binding. Contact Estuary support for assistance before using this option. | string |
Sample
captures:
${PREFIX}/${CAPTURE_NAME}:
endpoint:
connector:
image: "ghcr.io/estuary/source-sqlserver:v0"
config:
address: "<host>:1433"
database: "my_db"
user: "flow_capture"
credentials:
auth_type: UserPassword
password: "secret"
bindings:
- resource:
stream: ${TABLE_NAME}
namespace: dbo
primary_key: ["id"]
target: ${PREFIX}/${COLLECTION_NAME}
To authenticate to an Azure SQL Database with Azure IAM instead, replace the credentials block:
credentials:
auth_type: AzureIAM
azure_client_id: "11111111-2222-3333-4444-555555555555"
azure_tenant_id: "66666666-7777-8888-9999-000000000000"
Your capture definition will likely be more complex, with additional bindings for each table in the source database.
Learn more about capture definitions.
Specifying Estuary collection keys
Every Estuary collection must have a key. As long as your SQL Server tables have a primary key specified, the connector will set the corresponding collection's key accordingly.
In cases where a SQL Server table you want to capture doesn't have a primary key, you can manually add it to the collection definition during the capture creation workflow.
-
After you input the endpoint configuration and click Next, the tables in your database have been mapped to Estuary collections. Click each collection's Specification tab and identify a collection where
"key": [ ],is empty. -
Click inside the empty key value in the editor and input the name of column in the table to use as the key, formatted as a JSON pointer. For example
"key": ["/foo"],Make sure the key field is required, not nullable, and of an allowed type. Make any other necessary changes to the collection specification to accommodate this.
-
Repeat with other missing collection keys, if necessary.
-
Save and publish the capture as usual.