CDC: process what changed instead of rereading everything
Change data capture, or CDC, identifies changes after a known point so downstream processing can work incrementally.
Understand the idea
Imagine a shop with a million orders. A report-refresh job could reread every order each time, or process only the changes since its previous successful run. CDC supports the second approach, but it still needs a clear business key and reliable transaction boundaries.
| Concept | What it means |
|---|---|
| Source | The table where changes originate. |
| Stream | A named position in supported source change history. |
| Consumer | SQL that applies changes to another destination. |
| Task | The scheduler or trigger that runs that SQL. |
A concrete example
The stream starts after the two initial rows, so its initial result is empty. It does not automatically backfill existing records. SOURCE_ORDERS still contains both rows.
Remember: Plan a baseline separately from ongoing CDC; an empty new stream does not mean the source is empty.
Explain it step by step · full theory
Understand the concept
Imagine a shop with a million orders. A report-refresh job could reread every order each time, or process only the changes since its previous successful run. CDC supports the second approach, but it still needs a clear business key and reliable transaction boundaries.
A stream does not copy all source rows into a second table. It maintains an offset and exposes changes relative to source history. A task does not identify changed rows by itself; it runs SQL that may read a stream.
Walk through the behavior
We use two independent examples: SOURCE_ORDERS teaches standard-stream updates/deletes. Later ORDER_EVENTS is an immutable event feed used by the complete pipeline. Keeping them separate avoids mixing source-table CDC with application event semantics.
Create the sandbox once. A role needs container access, CREATE TABLE/STREAM/PROCEDURE/TASK as appropriate, source privileges, and compute access. Creating a stream may require enabling source change tracking, which requires source ownership or an owner-assisted setup.
Words used in this lesson
- Source
- The table where changes originate.
- Stream
- A named position in supported source change history.
- Consumer
- SQL that applies changes to another destination.
- Task
- The scheduler or trigger that runs that SQL.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
CDC: process what changed instead of rereading everything
Start with the source
Change data capture, or CDC, identifies changes after a known point so downstream processing can work incrementally.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Start with the source
Change data capture, or CDC, identifies changes after a known point so downstream processing can work incrementally.
- Follow the work
Imagine a shop with a million orders. A report-refresh job could reread every order each time, or process only the changes since its previous successful run. CDC supports the second approach, but it still needs a clear business key and reliable transaction boundaries.
- Explain the outcome
Plan a baseline separately from ongoing CDC; an empty new stream does not mean the source is empty.
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Manual learning lab; nothing runs on this website. Complete lesson 1 setup in L2_OBJECTS_LAB.M11_LAB and follow the lesson order. Use the same authorized role and warehouse for manual SQL. Task templates use <lab_warehouse>: replace it with an approved warehouse name. Do not activate several consumers against the same stream. Each task starts suspended; running or resuming it can consume compute credits.
Create a separate Module 11 sandbox
USE DATABASE L2_OBJECTS_LAB;
CREATE SCHEMA M11_LAB;
USE SCHEMA M11_LAB;
CREATE TABLE SOURCE_ORDERS (ORDER_ID NUMBER, AMOUNT NUMBER(12,2));
INSERT INTO SOURCE_ORDERS VALUES (101,100),(102,50);
CREATE STREAM SOURCE_CHANGES ON TABLE SOURCE_ORDERS;
SELECT * FROM SOURCE_CHANGES;What to expect and why
The stream starts after the two initial rows, so its initial result is empty. It does not automatically backfill existing records. SOURCE_ORDERS still contains both rows.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
How would you describe the source, stream and task to a beginner?
Compare your reasoning
The source holds records, the stream marks which changes remain to process, and the task runs the processing SQL.