Object reference · Lesson 1 of 8Detailed study · about 12 min

Stored query results: materialized views and dynamic tables

Materialized views and dynamic tables store query results. Snowflake maintains those results, but the two objects solve different problems and have different refresh rules.

Understand the idea

An ordinary view is a recipe. A materialized view also keeps a prepared result so repeated work can be reduced. It has restrictions on supported SQL and requires Enterprise Edition or higher. Do not assume any query can become a materialized view.

Key ideas in simple English
ConceptWhat it means
Materialized viewPrecomputes a supported query over one base table for query acceleration.
Dynamic tableMaintains a query-defined result for a transformation pipeline.
Target lagA desired freshness target for dynamic-table data, not a guaranteed schedule.
MaintenanceStored results need storage and compute to stay useful.

A concrete example

Northstar may accelerate a repeated sales total with a materialized view. A multi-step curated sales dataset may instead use dynamic tables.

Remember: Choose by query support and freshness needs, then account for maintenance cost.

Explain it step by step · full theory

Understand the idea

An ordinary view is a recipe. A materialized view also keeps a prepared result so repeated work can be reduced. It has restrictions on supported SQL and requires Enterprise Edition or higher. Do not assume any query can become a materialized view.

A dynamic table declares the result you want with a query. Snowflake schedules refresh work to maintain it. A refresh warehouse supplies compute. The chosen target lag expresses desired freshness relative to source data; workload and dependencies can prevent that target from being met.

Follow the example

The SQL is an optional dynamic-table illustration using lesson 1 ORDERS. LAB_WH must already exist and be authorized; the owning role needs warehouse USAGE and the necessary object privileges. Creation can initialize data and future refreshes consume resources, so read it first.

After a successful refresh of the original sample, TOTAL_AMOUNT is 100.00. If new orders arrive, this stored total is not promised to change instantly. Inspect refresh status before assuming that a dashboard has the newest data.

After initialization succeeds, the initial total is 100.00 for lesson 1 data. This example creates a maintained object, not a one-time SELECT result.

Words used in this lesson
Materialized view
Precomputes a supported query over one base table for query acceleration.
Dynamic table
Maintains a query-defined result for a transformation pipeline.
Target lag
A desired freshness target for dynamic-table data, not a guaranteed schedule.
Maintenance
Stored results need storage and compute to stay useful.

See how it works

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

Open the interactive explanation
Interactive explainer1 / 3

Stored query results: materialized views and dynamic tables

Northstar sales team
Business requirement

Start with the requirement

Northstar may accelerate a repeated sales total with a materialized view. A multi-step curated sales dataset may instead use dynamic tables.

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. Start with the requirement

    Northstar may accelerate a repeated sales total with a materialized view. A multi-step curated sales dataset may instead use dynamic tables.

  2. Choose the objects

    Compare the responsibilities: Materialized view: Precomputes a supported query over one base table for query acceleration.; Dynamic table: Maintains a query-defined result for a transformation pipeline.; Target lag: A desired freshness target for dynamic-table data, not a guaranteed schedule.

  3. Explain the outcome

    Choose by query support and freshness needs, then account for maintenance cost.

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.
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

Read-first example. Materialized views require Enterprise Edition or higher. Dynamic-table creation needs a supported query, authorized warehouse and source privileges; refreshes can incur ongoing costs.

Read the example

SQL · example
-- Optional: LAB_WH must exist and be authorized.
CREATE DYNAMIC TABLE L2_OBJECTS_LAB.SALES.ORDER_TOTAL
TARGET_LAG = '10 minutes'
WAREHOUSE = LAB_WH
AS SELECT SUM(AMOUNT) AS TOTAL_AMOUNT FROM L2_OBJECTS_LAB.SALES.ORDERS;
SELECT * FROM L2_OBJECTS_LAB.SALES.ORDER_TOTAL;

What to expect and why

After initialization succeeds, the initial total is 100.00 for lesson 1 data. This example creates a maintained object, not a one-time SELECT result.

Check your understanding

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

What does a ten-minute target lag promise?

Try it yourself

A dashboard needs a transformation with several joins. What should you investigate before choosing a maintained object?

Compare your reasoning

Check supported query operations, source dependencies, required freshness and maintenance cost. A target lag is a target rather than a fixed execution timetable; do not select a materialized view assuming all joins are supported.

Official sources and curriculum

Object reference · See module scope