能否在视图或物化视图上配置CDC追踪?基于Confluent、SQL Server与Debezium
Great question! Let's break this down clearly based on how Debezium integrates with SQL Server's native CDC capabilities:
Short Answer
No, you can't directly configure CDC tracking for regular views or materialized/indexed views using Debezium and SQL Server. Here's why, plus practical workarounds:
1. Regular Views
SQL Server's native CDC doesn't support tracking changes on views at all—views are just virtual, query-based representations of data pulled from underlying base tables. Since Debezium relies entirely on SQL Server's CDC to capture change events, there's no way to point Debezium directly at a view to get change data. Any "changes" you see in a view are just reflections of modifications to its underlying base tables.
2. Materialized/Indexed Views (SQL Server's Version)
Even though indexed views have physical storage, SQL Server CDC still doesn't support enabling CDC on them. CDC is built to track changes at the base table level, and updates to indexed views are automatically derived from base table modifications. Debezium's SQL Server connector also only works with standard tables, so you can't target these views for CDC tracking either.
Workarounds to Get Similar Behavior
If you need to stream data that mirrors a view's output, try these reliable options:
- Enable CDC on all base tables the view depends on: Capture changes from the underlying tables, then use Confluent's stream processing tools (like KSQLDB or Kafka Streams) to reconstruct the view's logic on the streaming side. This gives you real-time, consistent data that matches the view's output.
- Sync the view to a physical table: Create a dedicated table that replicates the view's data (using SQL Server triggers, scheduled jobs, or replication), then enable CDC on this physical table. Just keep in mind this approach may introduce minor data latency and requires extra maintenance to ensure consistency.
One quick config note: In your Debezium SQL Server connector settings, the table.include.list property only accepts actual table names—you'll get errors if you try to add view names here.
内容的提问来源于stack exchange,提问作者Samad Abbasi

