🟢 What is CDC?
CDC is a feature in databases that records every change—when a row is added, updated, or deleted.
Think of it like a CCTV camera for your database.
Whenever data changes, CDC quietly writes a note about it.
💡 Why is it useful?
-
You can send only new changes to another system (like a data warehouse) instead of copying everything.
-
You can trigger actions when data changes (e.g., send an email when an order ships).
-
It helps with auditing (who changed what and when).
⚙️ How it works (step by step)
-
Turn it on
-
An admin tells the database: “Watch this table for changes.”
-
-
Database watches the transaction log
-
Every insert, update, or delete is already recorded in the database log.
-
CDC reads that log.
-
-
Change table created
-
CDC puts details of each change into a special table (e.g.,
cdc.Orders_CT
). -
This table shows:
-
What kind of change happened (insert/update/delete)
-
Old and new values
-
The time of the change.
-
-
-
Your app reads the changes
-
Your app or ETL job asks: “Give me all changes since last time.”
-
It processes those and remembers the last point it read.
-
🧠 Simple Example
-
You have an Orders table.
-
You update order #5’s status to “Shipped.”
-
CDC writes a row into its change table:
“Order #5 changed from Pending → Shipped at 10:32 AM.”
✅ Good Things
-
No triggers needed: It uses the existing transaction log.
-
Fast: Only new changes are read.
-
Real-time: You see changes almost immediately.
⚠️ Things to keep in mind
-
Change tables can grow big—set cleanup rules.
-
Only users with permission should read CDC data.
🏁 Quick Summary
CDC = Automatic change tracker for your database.
It watches every insert, update, or delete and stores those details in a special table, so other apps can easily know exactly what changed without scanning everything.