By Rohit Ray · Independent educational lesson · Explore this visual lab

Module 12 · Lesson 2 of 9Detailed study · about 20 min

Create the first stored transformation

The AS SELECT query defines which source rows belong in a dynamic table. Refreshing maintains that query result, including removals when rows stop qualifying.

Understand the idea

Our clean layer contains paid orders only. Initially orders 101 and 102 qualify. If an order later becomes cancelled, the stored result must remove it; this is not an append-only copy.

Key ideas in simple English
ConceptWhat it means
TARGET_LAGA freshness objective, not a CRON schedule.
WAREHOUSECompute used for refresh work.
INITIALIZEWhen the first result is built.
ON_CREATEBuild the initial result as part of creation.

A concrete example

Our clean layer contains paid orders only. Initially orders 101 and 102 qualify. If an order later becomes cancelled, the stored result must remove it; this is not an append-only copy.

Remember: SELECT reads its stored result. Initialization or a later successful refresh updates that result.

Explain it step by step · full theory

Understand the concept

Our clean layer contains paid orders only. Initially orders 101 and 102 qualify. If an order later becomes cancelled, the stored result must remove it; this is not an append-only copy.

Choose INCREMENTAL explicitly for the small supported filter/projection query. This makes incompatible definitions fail instead of silently relying on an AUTO choice. ON_CREATE performs the initial population, so the CREATE may take time or fail on permissions or query errors.

Apply it to our pipeline

Use DOWNSTREAM for this intermediate layer. After initialization it has no independent refresh schedule; the customer-total table in the next lesson will drive it. A SELECT against CLEAN_ORDERS does not ask Snowflake to refresh it.

Replace YOUR_LAB_WH before running. The refresh runs under the owner role’s privileges; a learner’s interactive SELECT permission is not a substitute for the refresh owner retaining source and warehouse access.

Words used in this lesson
TARGET_LAG
A freshness objective, not a CRON schedule.
WAREHOUSE
Compute used for refresh work.
INITIALIZE
When the first result is built.
ON_CREATE
Build the initial result as part of creation.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 2

Create the first stored transformation

RAW_ORDERS
CLEAN_ORDERS
CUSTOMER_TOTALS

Read the dependency

The AS SELECT query defines which source rows belong in a dynamic table. Refreshing maintains that query result, including removals when rows stop qualifying.

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
  1. Read the dependency

    The AS SELECT query defines which source rows belong in a dynamic table. Refreshing maintains that query result, including removals when rows stop qualifying.

  2. Observe the result

    After successful initialization: 101/A/100 and 102/A/50. Inspect refresh_mode and scheduling_state in SHOW output.

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.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. 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.
  3. 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.
  4. 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 Snowflake practice only. This website does not run SQL or provision compute. Refreshing dynamic tables uses billable resources.

Create the first stored transformation — manual SQL

Definition: The AS SELECT query defines which source rows belong in a dynamic table. Refreshing maintains that query result, including removals when rows stop qualifying.

When to use: Practise in the isolated M12_LAB schema.

Example: After successful initialization: 101/A/100 and 102/A/50. Inspect refresh_mode and scheduling_state in SHOW output.

SQL · example
CREATE DYNAMIC TABLE CLEAN_ORDERS
 TARGET_LAG=DOWNSTREAM
 WAREHOUSE=YOUR_LAB_WH
 REFRESH_MODE=INCREMENTAL
 INITIALIZE=ON_CREATE
AS SELECT ORDER_ID,CUSTOMER_ID,AMOUNT
 FROM RAW_ORDERS WHERE STATUS='PAID';
SELECT * FROM CLEAN_ORDERS ORDER BY ORDER_ID;
SHOW DYNAMIC TABLES LIKE 'CLEAN_ORDERS' IN SCHEMA L2_OBJECTS_LAB.M12_LAB;

What to expect and why

After successful initialization: 101/A/100 and 102/A/50. Inspect refresh_mode and scheduling_state in SHOW output.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Does querying CLEAN_ORDERS force it to refresh?

Try it yourself

Explain why: Does querying CLEAN_ORDERS force it to refresh?

Compare your reasoning

SELECT reads its stored result. Initialization or a later successful refresh updates that result.

Official sources and curriculum

Module 12 · See module scope