CertSafari
    Snowflake SnowPro Advanced: Data Engineer (DEA-C02)· Lessons

    Domain 1 · Lesson 4/22

    Streams, tasks and dynamic tables for continuous transformation

    Design, build, and troubleshoot continuous data pipelines.

    10 min read
    4% of exam
    7 sources
    Published 20 Oct 2026
    Docs as of 18 Oct 2026

    What you will be able to do

    • Use a stream and a triggered task to process only changed rows
    • Choose between a dynamic table, streams and tasks, and a materialized view for a pipeline step
    • Orchestrate ingestion procedures with Snowflake Scripting, scheduled notebooks and the SQL API

    1.Streams record what changed since you last looked

    Once raw data has landed, the next step usually needs only the rows that are new or changed. A stream provides this kind of change data capture. It sits on a table, such as a staging table, and exposes the row-level changes made between two transactional points in time. Each change row carries METADATA$ACTION, METADATA$ISUPDATE and METADATA$ROW_ID, which tell you what kind of change it was.

    A standard (delta) stream and an append-only stream on the same tablesql
    -- Create a standard stream on the source table.
    create or replace  stream delta_s on table t;
    
    -- Create an append-only stream on the source table.
    create or replace  stream append_only_s on table t append_only=true;

    The two stream types answer different questions. The standard stream nets the changes, so the inserted-then-deleted row disappears and two INSERT rows remain. The append-only stream records inserts only and ignores the delete, so it still shows all three rows. Use append-only when the source only receives inserts, such as an event log, and use a standard stream when updates and deletes need to reach the target.

    A stream's position moves only when its changes are consumed. A task that reads the stream either consumes the change data in a DML statement or skips the run because nothing has changed. Selecting from a stream doesn't consume it. A downstream MERGE that reads the stream does.

    Checkpoint 1 of 5· Check yourself

    A task runs a MERGE that reads a stream on a staging table. On one run, nothing in the staging table has changed since the previous MERGE consumed the stream. What happens?

    Sources12

    2.Tasks run the step on a schedule or on a trigger

    A task runs one SQL statement, which can be a stored procedure call. It runs on a schedule or when a trigger fires, such as new data arriving. Tasks can be chained into a task graph, a directed acyclic graph (DAG) in which child tasks run after their parent, for multi-step processing.

    A triggered task is created with CREATE TASK, a WHEN clause naming the stream (the condition is SYSTEM$STREAM_HAS_DATA), and no SCHEDULE parameter. It uses no compute until the trigger fires. For a task on a user-managed warehouse you add the WAREHOUSE parameter. Without it, Snowflake supplies serverless compute. Triggered tasks work on streams over tables, views, dynamic tables, Iceberg tables, shares and directory tables. They aren't supported for hybrid tables or for streams on external tables. A directory table must be refreshed before its changes can trigger a task.

    Checkpoint 2 of 5· Check yourself

    New rows land in a staging table, and a stream sits on that table. Each batch has to be processed by an existing stored procedure that holds the multi-step upsert logic. Processing should start as soon as changes arrive and use no compute while the stream is empty. Which design fits?

    Sources13

    3.Dynamic tables declare the result instead of the steps

    Streams and tasks are procedural: you write the steps and decide when they run. A dynamic table is declarative. You write a SELECT and a TARGET_LAG, and Snowflake tracks the base tables and refreshes the result to stay within that lag.

    A dynamic table that cleans raw orders with a 10-minute target lagsql
    CREATE OR ALTER DYNAMIC TABLE dt_orders
        TARGET_LAG = '10 minutes'
        WAREHOUSE = transform_wh
        REFRESH_MODE = INCREMENTAL
    AS
        SELECT
            order_id,
            customer_id,
            order_date,
            TRIM(UPPER(product_name)) AS product_name,
            quantity,
            unit_price,
            quantity * unit_price AS line_total,
            order_status
        FROM raw_orders
        WHERE order_status != 'returned';

    Target lag is a goal, not a guarantee. The actual lag can exceed it when a refresh takes longer than expected, and the minimum is 60 seconds. The refresh mode controls how much work each refresh does:

    • INCREMENTAL processes only the rows that changed.
    • FULL recomputes the whole result.
    • AUTO picks one of those at creation time, depending on whether the query supports incremental refresh.
    • ADAPTIVE is incremental, but reinitializes after large upstream changes.
    • CUSTOM_INCREMENTAL lets you write the refresh logic as DML.

    When one dynamic table reads another, Snowflake infers the dependency graph and refreshes the tables in order against a consistent snapshot. An intermediate table can use TARGET_LAG = DOWNSTREAM so it refreshes only when something downstream needs it. Costs come from three places: the warehouse that runs each refresh, cloud services (more of it with shorter lag), and storage.

    Picking the tool for a pipeline step
    RequirementDynamic tableStreams and tasksMaterialized view
    Joins or aggregations across tablesPreferredPossibleNo (single table only)
    Always-current data with no lagNo (minimum TARGET_LAG is 1 minute)Possible (not zero-lag)Preferred
    MERGE, stored procedures, IF/ELSE, external functionsNoPreferredNo
    UDFs in the transformPossible (scalar UDFs and UDTFs with explicit column lists; no Snowpark)PreferredNo

    A materialized view is the right step when you need a precomputed result over a single table that is always current (Materialized views). Once the step needs a join or multiple stages, use a dynamic table. UDFs can go inside the transform, but a dynamic table accepts only scalar UDFs, and UDTFs only in lateral joins with explicit column lists (UDF types (scalar, UDTF, UDAF) and handler languages). For stored procedures or external functions, use streams and tasks.

    Checkpoint 3 of 5· Fill the gap

    This dynamic table must stay no more than 10 minutes behind raw_orders. Which parameter completes the definition?

    CREATE OR ALTER DYNAMIC TABLE dt_orders
         ?  = '10 minutes'
        WAREHOUSE = transform_wh
        REFRESH_MODE = INCREMENTAL
    AS
        SELECT
            order_id,
            customer_id,
            order_date,
            TRIM(UPPER(product_name)) AS product_name,
            quantity,
            unit_price,
            quantity * unit_price AS line_total,
            order_status
        FROM raw_orders
        WHERE order_status != 'returned';

    Checkpoint 4 of 5· Check yourself

    A team runs a stream and a triggered task that call a stored procedure. The procedure does a multi-branch MERGE upsert. They want to replace this with a single dynamic table whose definition calls the same procedure. What is the outcome?

    Sources4

    4.Scripting, notebooks and the SQL API drive the pipeline

    Multi-step ingestion (load, validate, merge, log) needs procedural control. Snowflake Scripting adds variables, IF and CASE, loops, cursors and exception handling to SQL. You can use it inside a stored procedure or as an anonymous block run directly. A common pattern is a task that calls a Scripting procedure, where an exception handler records the failure instead of leaving a partial load (Stored procedures: Snowflake Scripting, JavaScript and Snowpark).

    A notebook can serve as the pipeline. When a notebook is scheduled, a task runs it top to bottom. A notebook whose cells call ingestion procedures in order becomes a scheduled pipeline (Snowflake Notebooks). An external scheduler such as Airflow can run the same notebook with EXECUTE NOTEBOOK and pass arguments.

    Running a notebook with arguments from a task or an external schedulersql
    EXECUTE NOTEBOOK DB.SCHEMA.NOTEBOOK_NAME('--env staging --tablename staging-table');

    Scheduled notebooks fail in two common ways. The task's owner role must match the notebook's owner role, and renaming a notebook breaks the task that calls it until you redefine the task. Run history covers only the last seven days.

    When the orchestrator runs outside Snowflake, the Snowflake SQL API lets it control Snowflake over REST. It can submit SQL statements, including several per request, explicit transactions and stored procedure calls. It can check a statement's execution status and cancel it. Requests authenticate with OAuth or key pair. A key pair JWT uses the same claims as the one the Snowpipe REST API accepts. The SQL API runs SQL statements, while insertFiles only queues files for a pipe.

    Checkpoint 5 of 5· Check yourself

    An Airflow DAG running outside Snowflake has to call a stored procedure that merges staged orders. It must then poll until that statement finishes, and cancel the statement if it runs too long. Which interface fits this orchestration?

    Sources567

    Sources

    (7)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “A stream allows querying and consuming a set of changes to a table, at the row level, between two transactional points of time.”
      ↩︎ Streams record what changed since you last looked
      “Each time a task runs, it can either consume the change data or skip the current run if no change data exists.”
      ↩︎ Streams record what changed since you last looked
      “You can use task graphs to chain tasks together, defining directed acyclic graphs (DAGs) to support more complex periodic processing.”
      ↩︎ Tasks run the step on a schedule or on a trigger
      “A task object runs a SQL statement, which can include calls to stored procedures.”
      ↩︎ Checkpoint
    2. 2.
    3. 3.
      “Triggered tasks don’t use compute resources until the event is triggered.”
      ↩︎ Tasks run the step on a schedule or on a trigger
      “Define the target stream using the WHEN clause. (Do not include the SCHEDULE parameter.)”
      ↩︎ Exam trap 1
      “This eliminates the need to poll a source frequently when the availability of new data is unpredictable.”
      ↩︎ Prediction
    4. 4.
      “You specify a SELECT query and a target lag, and Snowflake tracks dependencies and refreshes the data on schedule.”
      ↩︎ Dynamic tables declare the result instead of the steps
      “AUTO lets Snowflake choose at creation time based on whether the definition supports incremental refresh.”
      ↩︎ Dynamic tables declare the result instead of the steps
      “Need stored procedures or external functions in the definition.”
      ↩︎ Exam trap 2
      “Need stored procedures or external functions in the definition.”
      ↩︎ Checkpoint
    5. 5.
      “Snowflake Scripting is an extension to Snowflake SQL that adds support for procedural logic.”
      ↩︎ Scripting, notebooks and the SQL API drive the pipeline
    6. 7.
      “Use OAuth or Key Pair to authenticate with the Snowflake server.”
      ↩︎ Scripting, notebooks and the SQL API drive the pipeline
      “Check the status of the execution of a statement.”
      ↩︎ Checkpoint

    Ready to test yourself?

    Practise the 16 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.