In this post we are going to cover dynamic tables in Snowflake.
A dynamic table is a query you save, like a view, except that it holds rows. You write the query you actually wanted and you declare how stale the answer is allowed to be. You never write a refresh. Snowflake works out when to run it and what to change.
We will start by taking a join that a materialized view refused in Episode 109 and building it as a dynamic table instead. Then we will ask the catalog what sort of object we have just made, try to write to it, let it go out of date on purpose, and refresh it by hand.
Every query below was run on a real Snowflake account, and every result you see is the output it gave back.
Episode 110 of the Snowflake SQL: Zero to Hero series on TechBrothersIT.
- Let's create some sample data
- Let's build the join a materialized view refused
- Now let's try the other shapes it refused
- So what does the catalog think these are?
- Now let's ask SHOW DYNAMIC TABLES instead
- Can we write to it? It is called a table
- Now let's let it fall behind on purpose
- Let's refresh it by hand and watch what it reports
- What happens when we suspend one?
- Now a dynamic table on top of a dynamic table
- What happens when we drop a table it depends on?
- One last thing: let's tidy up
Let's create some sample data
We need two tables. One holds orders. The other holds a manager for each region, so that we have something to join to.
Copy this into a Snowflake worksheet and run it once.
-- Sample data for this post.
-- Two small tables: orders, and a manager for each region.
USE DATABASE DEMO_DB;
USE SCHEMA PUBLIC;
CREATE OR REPLACE TABLE ORDERS_T110 (
ORDER_ID INT,
REGION VARCHAR(20),
CUSTOMER VARCHAR(30),
AMOUNT NUMBER(10,2)
);
INSERT INTO ORDERS_T110 (ORDER_ID, REGION, CUSTOMER, AMOUNT)
SELECT 1, 'north', 'Ana', 100.00 UNION ALL
SELECT 2, 'north', 'Ben', 250.00 UNION ALL
SELECT 3, 'south', 'Cleo', 75.50 UNION ALL
SELECT 4, 'south', 'Dan', 310.00 UNION ALL
SELECT 5, 'east', 'Eve', 40.00 UNION ALL
SELECT 6, 'east', 'Finn', 60.00;
CREATE OR REPLACE TABLE REGIONS_T110 (
REGION VARCHAR(20),
MANAGER VARCHAR(30)
);
INSERT INTO REGIONS_T110 (REGION, MANAGER)
SELECT 'north', 'Nadia' UNION ALL
SELECT 'south', 'Sam' UNION ALL
SELECT 'east', 'Eli';Let's look at the orders first.
SELECT ORDER_ID, REGION, CUSTOMER, AMOUNT FROM ORDERS_T110 ORDER BY ORDER_ID;| ORDER_ID | REGION | CUSTOMER | AMOUNT |
|---|---|---|---|
| 1 | north | Ana | 100.00 |
| 2 | north | Ben | 250.00 |
| 3 | south | Cleo | 75.50 |
| 4 | south | Dan | 310.00 |
| 5 | east | Eve | 40.00 |
| 6 | east | Finn | 60.00 |
Six orders across three regions, with an amount on each one. Nothing unusual about it.
And the regions.
SELECT REGION, MANAGER FROM REGIONS_T110 ORDER BY REGION;| REGION | MANAGER |
|---|---|
| east | Eli |
| north | Nadia |
| south | Sam |
Three regions and a manager for each. Nadia has the north, Sam has the south, Eli has the east.
Let's build the join a materialized view refused
In Episode 109 we tried to save this exact join as a materialized view and Snowflake would not have it. A materialized view reads from one table, and this join reads from two.
So let's write the same join as a dynamic table. There are two things to declare that a view does not ask for: a TARGET_LAG, which is how stale we will let the answer be, and a WAREHOUSE, which is what does the refreshing.
CREATE OR REPLACE DYNAMIC TABLE DT_JOINED_T110
TARGET_LAG = '1440 minutes'
WAREHOUSE = COMPUTE_WH
AS
SELECT O.ORDER_ID, O.REGION, R.MANAGER, O.AMOUNT
FROM ORDERS_T110 O
JOIN REGIONS_T110 R ON R.REGION = O.REGION;| status |
|---|
| Dynamic table DT_JOINED_T110 successfully created. |
Created. Same join, no refusal, different kind of object.
Now let's read from it straight away, with nothing refreshed and nothing waited for.
SELECT ORDER_ID, REGION, MANAGER, AMOUNT FROM DT_JOINED_T110 ORDER BY ORDER_ID;| ORDER_ID | REGION | MANAGER | AMOUNT |
|---|---|---|---|
| 1 | north | Nadia | 100.00 |
| 2 | north | Nadia | 250.00 |
| 3 | south | Sam | 75.50 |
| 4 | south | Sam | 310.00 |
| 5 | east | Eli | 40.00 |
| 6 | east | Eli | 60.00 |
It already has rows. Ana and Ben came back under Nadia, Cleo and Dan under Sam, Eve and Finn under Eli. All six orders, the moment the object existed.
A TARGET_LAG of '1440 minutes' is one day. Everything in this post uses a lag of a day so that nothing here is waiting on a clock. Every refresh we do is asked for by hand.
Now let's try the other shapes it refused
A materialized view also turned down a window function in Episode 109. Let's write that one as a dynamic table.
CREATE OR REPLACE DYNAMIC TABLE DT_RANKED_T110
TARGET_LAG = '1440 minutes'
WAREHOUSE = COMPUTE_WH
AS
SELECT ORDER_ID, REGION, AMOUNT,
ROW_NUMBER() OVER (PARTITION BY REGION ORDER BY AMOUNT DESC) AS RN
FROM ORDERS_T110;| status |
|---|
| Dynamic table DT_RANKED_T110 successfully created. |
Accepted. And it is populated too.
SELECT ORDER_ID, REGION, AMOUNT, RN FROM DT_RANKED_T110
ORDER BY REGION, RN;| ORDER_ID | REGION | AMOUNT | RN |
|---|---|---|---|
| 6 | east | 60.00 | 1 |
| 5 | east | 40.00 | 2 |
| 2 | north | 250.00 | 1 |
| 1 | north | 100.00 | 2 |
| 4 | south | 310.00 | 1 |
| 3 | south | 75.50 | 2 |
Six rows, with a rank inside each region. The highest amount in each region got RN of 1.
And one object holding two common table expressions and a union
Let's write one more. This one has two WITH clauses and a UNION ALL between them, which is a shape nobody expects a saved query to take.
CREATE OR REPLACE DYNAMIC TABLE DT_UNIONED_T110
TARGET_LAG = '1440 minutes'
WAREHOUSE = COMPUTE_WH
AS
WITH BIG AS (SELECT ORDER_ID, AMOUNT FROM ORDERS_T110 WHERE AMOUNT >= 100),
SMALL AS (SELECT ORDER_ID, AMOUNT FROM ORDERS_T110 WHERE AMOUNT < 100)
SELECT ORDER_ID, AMOUNT, 'big' AS SIZE_BAND FROM BIG
UNION ALL
SELECT ORDER_ID, AMOUNT, 'small' AS SIZE_BAND FROM SMALL;| status |
|---|
| Dynamic table DT_UNIONED_T110 successfully created. |
SELECT ORDER_ID, AMOUNT, SIZE_BAND FROM DT_UNIONED_T110 ORDER BY ORDER_ID;| ORDER_ID | AMOUNT | SIZE_BAND |
|---|---|---|
| 1 | 100.00 | big |
| 2 | 250.00 | big |
| 3 | 75.50 | small |
| 4 | 310.00 | big |
| 5 | 40.00 | small |
| 6 | 60.00 | small |
Six rows again, each one labelled big or small.
So let's count all of them in one row.
SELECT (SELECT COUNT(*) FROM DT_JOINED_T110) AS ROWS_FROM_A_JOIN,
(SELECT COUNT(*) FROM DT_RANKED_T110) AS ROWS_FROM_A_WINDOW,
(SELECT COUNT(*) FROM DT_UNIONED_T110) AS ROWS_FROM_A_UNION_AND_CTE;| ROWS_FROM_A_JOIN | ROWS_FROM_A_WINDOW | ROWS_FROM_A_UNION_AND_CTE |
|---|---|---|
| 6 | 6 | 6 |
Three dynamic tables, six rows in each. The third column is named for both the union and the common table expressions, because those two are in the same object — DT_UNIONED_T110 is one statement that has both.
The spoken version of this episode calls these four shapes a materialized view refused, and the grid above has three columns. Two things are worth getting straight. Three dynamic tables were built, and the union and the common table expressions share the third one. And of these shapes, the ones a materialized view actually refused in Episode 109 were the join and the window function. A UNION ALL and a WITH clause were both accepted as materialized views in that episode, which was the surprise of it.
So what does the catalog think these are?
We have three dynamic tables and two ordinary tables in the schema now. Let's ask INFORMATION_SCHEMA.TABLES about all five of them at once.
SELECT TABLE_NAME, TABLE_TYPE, IS_INSERTABLE_INTO, ROW_COUNT
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC' AND RIGHT(TABLE_NAME, 5) = '_T110'
ORDER BY TABLE_NAME;| TABLE_NAME | TABLE_TYPE | IS_INSERTABLE_INTO | ROW_COUNT |
|---|---|---|---|
| DT_JOINED_T110 | BASE TABLE | NO | 6 |
| DT_RANKED_T110 | BASE TABLE | NO | 6 |
| DT_UNIONED_T110 | BASE TABLE | NO | 6 |
| ORDERS_T110 | BASE TABLE | YES | 6 |
| REGIONS_T110 | BASE TABLE | YES | 3 |
Every one of them is a BASE TABLE. The dynamic tables are not listed as views and they are not listed as anything of their own. They are tables.
And they have a ROW_COUNT, which a view never has, because a view holds nothing to count.
Look at the column in the middle. IS_INSERTABLE_INTO says NO for the three dynamic tables and YES for ORDERS_T110 and REGIONS_T110. In this grid that is the only thing that tells them apart.
Now let's ask SHOW DYNAMIC TABLES instead
SHOW DYNAMIC TABLES knows a great deal more than the catalog view does. Here is the whole thing.
SHOW DYNAMIC TABLES IN SCHEMA PUBLIC;| created_on | name | database_name | schema_name | cluster_by | rows | bytes | owner | target_lag | refresh_mode | refresh_mode_reason | warehouse | comment | text | automatic_clustering | scheduling_state | last_suspended_on | is_clone | is_replica | is_iceberg | data_timestamp | owner_role_type | execute_as_user | secondary_role_names | insert_only_inputs | immutable_where | initialization_warehouse | backfill_from | scheduler | frozen_where | configured_refresh_mode |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2026-09-28 18:26:01.695000-07:00 | DT_JOINED_T110 | DEMO_DB | PUBLIC | 6 | 1536 | ACCOUNTADMIN | 1 day | INCREMENTAL | NULL | COMPUTE_WH | CREATE OR REPLACE DYNAMIC TABLE DT_JOINED_T110 lag = '1 day' refresh_mode = 'AUTO' initialize = 'ON_CREATE' warehouse = COMPUTE_WH AS SELECT O.ORDER_ID, O.REGION, R.MANAGER, O.AMOUNT FROM ORDERS_T110 O JOIN REGIONS_T110 R ON R.REGION = O.REGION | OFF | ACTIVE | NULL | false | false | false | 2026-09-28 18:26:02.712000-07:00 | ROLE | NULL | NULL | false | NULL | NULL | NULL | NULL | AUTO | |||
| 2026-09-28 18:26:04.462000-07:00 | DT_RANKED_T110 | DEMO_DB | PUBLIC | 6 | 1536 | ACCOUNTADMIN | 1 day | INCREMENTAL | NULL | COMPUTE_WH | CREATE OR REPLACE DYNAMIC TABLE DT_RANKED_T110 lag = '1 day' refresh_mode = 'AUTO' initialize = 'ON_CREATE' warehouse = COMPUTE_WH AS SELECT ORDER_ID, REGION, AMOUNT, ROW_NUMBER() OVER (PARTITION BY REGION ORDER BY AMOUNT DESC) AS RN FROM ORDERS_T110 | OFF | ACTIVE | NULL | false | false | false | 2026-09-28 18:26:04.969000-07:00 | ROLE | NULL | NULL | false | NULL | NULL | NULL | NULL | AUTO | |||
| 2026-09-28 18:26:06.378000-07:00 | DT_UNIONED_T110 | DEMO_DB | PUBLIC | 6 | 1536 | ACCOUNTADMIN | 1 day | INCREMENTAL | NULL | COMPUTE_WH | CREATE OR REPLACE DYNAMIC TABLE DT_UNIONED_T110 lag = '1 day' refresh_mode = 'AUTO' initialize = 'ON_CREATE' warehouse = COMPUTE_WH AS WITH BIG AS (SELECT ORDER_ID, AMOUNT FROM ORDERS_T110 WHERE AMOUNT >= 100), SMALL AS (SELECT ORDER_ID, AMOUNT FROM ORDERS_T110 WHERE AMOUNT < 100) SELECT ORDER_ID, AMOUNT, 'big' AS SIZE_BAND FROM BIG UNION ALL SELECT ORDER_ID, AMOUNT, 'small' AS SIZE_BAND FROM SMALL | OFF | ACTIVE | NULL | false | false | false | 2026-09-28 18:26:06.866000-07:00 | ROLE | NULL | NULL | false | NULL | NULL | NULL | NULL | AUTO |
That is a lot to read, so let's pull out the columns that matter. We can do that because the output of the last query is available again through RESULT_SCAN, which is the subject of the next post.
SELECT "name", "target_lag", "refresh_mode", "scheduling_state", "rows"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%T110'
ORDER BY "name";| name | target_lag | refresh_mode | scheduling_state | rows |
|---|---|---|---|---|
| DT_JOINED_T110 | 1 day | INCREMENTAL | ACTIVE | 6 |
| DT_RANKED_T110 | 1 day | INCREMENTAL | ACTIVE | 6 |
| DT_UNIONED_T110 | 1 day | INCREMENTAL | ACTIVE | 6 |
target_lag says 1 day, which is exactly what we declared, written back to us in different words. scheduling_state says ACTIVE, so Snowflake is willing to refresh them.
And refresh_mode says INCREMENTAL. That means Snowflake has worked out how to apply only what changed, rather than running the whole query again.
But we never asked for incremental
Let's look at what Snowflake stored when it created the first one.
SELECT GET_DDL('TABLE', 'DT_JOINED_T110') AS THE_STORED_DEFINITION;| THE_STORED_DEFINITION |
|---|
| create or replace dynamic table DT_JOINED_T110( ORDER_ID, REGION, MANAGER, AMOUNT ) target_lag = '1 day' refresh_mode = AUTO initialize = ON_CREATE warehouse = COMPUTE_WH as SELECT O.ORDER_ID, O.REGION, R.MANAGER, O.AMOUNT FROM ORDERS_T110 O JOIN REGIONS_T110 R ON R.REGION = O.REGION; |
Two words in there we never typed. refresh_mode = AUTO is what we asked for by saying nothing, and INCREMENTAL is what AUTO turned into. And initialize = ON_CREATE is why the table had rows the moment it existed.
So one column tells you what you asked for and another tells you what you got, and neither of them is a word you wrote.
Can we write to it? It is called a table
The catalog calls it a base table, so the obvious thing to try is writing to it. Let's insert one row.
INSERT INTO DT_JOINED_T110 (ORDER_ID, REGION, MANAGER, AMOUNT)
SELECT 99, 'west', 'Wes', 1.00;002706 (23001): SQL Compilation error: Invalid Operation INSERT on Dynamic Table
Invalid Operation INSERT on Dynamic Table. Let's try an update.
UPDATE DT_JOINED_T110 SET AMOUNT = 0 WHERE ORDER_ID = 1;002706 (23001): SQL Compilation error: Invalid Operation UPDATE on Dynamic Table
The same sentence with a different verb. A delete, then.
DELETE FROM DT_JOINED_T110 WHERE ORDER_ID = 1;002706 (23001): SQL Compilation error: Invalid Operation DELETE on Dynamic Table
And a truncate, which does not name a single row.
TRUNCATE TABLE DT_JOINED_T110;002706 (23001): SQL Compilation error: Invalid Operation TRUNCATE on Dynamic Table
Four write statements, four refusals, the same error code and the same sentence every time. Only the verb changes.
And nothing got through.
SELECT COUNT(*) AS ROWS_STILL_PRESENT FROM DT_JOINED_T110;| ROWS_STILL_PRESENT |
|---|
| 6 |
What is in a dynamic table is the query's business. It is not yours, and this is where IS_INSERTABLE_INTO of NO stops being a detail in a catalog view.
Now let's let it fall behind on purpose
This is the part that makes a dynamic table different from a view. A view computes every time you read it, so it is never out of date. A dynamic table holds rows, so it can be.
First let's write down where it stands.
SELECT COUNT(*) AS ROWS_BEFORE, SUM(AMOUNT) AS TOTAL_BEFORE FROM DT_JOINED_T110;| ROWS_BEFORE | TOTAL_BEFORE |
|---|---|
| 6 | 835.50 |
Hold on to those two numbers. Now let's add one more order to the base table.
INSERT INTO ORDERS_T110 (ORDER_ID, REGION, CUSTOMER, AMOUNT)
SELECT 7, 'north', 'Gus', 1000.00;| number of rows inserted |
|---|
| 1 |
SELECT COUNT(*) AS ROWS_IN_THE_BASE_TABLE, SUM(AMOUNT) AS TOTAL_IN_THE_BASE
FROM ORDERS_T110;| ROWS_IN_THE_BASE_TABLE | TOTAL_IN_THE_BASE |
|---|---|
| 7 | 1835.50 |
The base table has grown and so has its total. Now let's ask the dynamic table the same question.
SELECT COUNT(*) AS ROWS_IN_THE_DYNAMIC_TABLE, SUM(AMOUNT) AS TOTAL_IN_IT
FROM DT_JOINED_T110;| ROWS_IN_THE_DYNAMIC_TABLE | TOTAL_IN_IT |
|---|---|
| 6 | 835.50 |
It has not moved. Same count, same total as before the insert.
Here they are side by side.
SELECT (SELECT COUNT(*) FROM ORDERS_T110) AS BASE_ROWS,
(SELECT COUNT(*) FROM DT_JOINED_T110) AS DYNAMIC_TABLE_ROWS;| BASE_ROWS | DYNAMIC_TABLE_ROWS |
|---|---|
| 7 | 6 |
Seven in the base table, six in the dynamic table. It is behind, and it is allowed to be behind, because we said the answer could be a day old. A view would have said seven.
Let's refresh it by hand and watch what it reports
We do not have to wait for the clock. We can ask for a refresh, and the statement hands back its own report of what it did.
ALTER DYNAMIC TABLE DT_JOINED_T110 REFRESH;| dt_name | statistics | refreshed_dt_count | data_timestamp |
|---|---|---|---|
| DEMO_DB.PUBLIC.DT_JOINED_T110 | {"insertedRows":1,"copiedRows":0,"deletedRows":0} | 1 | 2026-09-28 18:26:12.874000-07:00 |
Read the statistics column. One row inserted, nothing copied, nothing deleted. It did not rebuild the table, it applied the one change. And refreshed_dt_count says one object was refreshed, which will matter later on.
Now let's read the table again.
SELECT ORDER_ID, REGION, MANAGER, AMOUNT FROM DT_JOINED_T110 ORDER BY ORDER_ID;| ORDER_ID | REGION | MANAGER | AMOUNT |
|---|---|---|---|
| 1 | north | Nadia | 100.00 |
| 2 | north | Nadia | 250.00 |
| 3 | south | Sam | 75.50 |
| 4 | south | Sam | 310.00 |
| 5 | east | Eli | 40.00 |
| 6 | east | Eli | 60.00 |
| 7 | north | Nadia | 1000.00 |
The seventh order is there, with Nadia against it, worked out by the join.
SELECT (SELECT COUNT(*) FROM ORDERS_T110) AS BASE_ROWS,
(SELECT COUNT(*) FROM DT_JOINED_T110) AS DYNAMIC_TABLE_ROWS;| BASE_ROWS | DYNAMIC_TABLE_ROWS |
|---|---|
| 7 | 7 |
Caught up, because we asked it to be.
What happens when we suspend one?
A dynamic table can have its lag changed and can be stopped. Let's do both to the ranked one and leave the other two alone.
ALTER DYNAMIC TABLE DT_RANKED_T110 SET TARGET_LAG = '2880 minutes';| status |
|---|
| Statement executed successfully. |
ALTER DYNAMIC TABLE DT_RANKED_T110 SUSPEND;| status |
|---|
| Statement executed successfully. |
Now let's see what that did. We run the SHOW again so that it is the last statement, and then read three columns out of it.
SHOW DYNAMIC TABLES IN SCHEMA PUBLIC;SELECT "name", "target_lag", "scheduling_state"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%T110'
ORDER BY "name";| name | target_lag | scheduling_state |
|---|---|---|
| DT_JOINED_T110 | 1 day | ACTIVE |
| DT_RANKED_T110 | 2 days | SUSPENDED |
| DT_UNIONED_T110 | 1 day | ACTIVE |
DT_RANKED_T110 says SUSPENDED, and its lag now reads 2 days. The other two are still ACTIVE on a lag of a day.
So can we still read a suspended dynamic table?
SELECT ORDER_ID, REGION, RN FROM DT_RANKED_T110 ORDER BY REGION, RN;| ORDER_ID | REGION | RN |
|---|---|---|
| 6 | east | 1 |
| 5 | east | 2 |
| 2 | north | 1 |
| 1 | north | 2 |
| 4 | south | 1 |
| 3 | south | 2 |
Yes. All the rows it was holding are still there and still readable. Suspend stops the refreshing. It does not stop the reading.
Let's start it again before we move on.
ALTER DYNAMIC TABLE DT_RANKED_T110 RESUME;| status |
|---|
| Statement executed successfully. |
SELECT COUNT(*) AS ROWS_PRESENT FROM DT_RANKED_T110;| ROWS_PRESENT |
|---|
| 6 |
Now a dynamic table on top of a dynamic table
This is the best thing in the episode. A dynamic table can read from another dynamic table, and when it does it can declare its lag as DOWNSTREAM instead of a length of time. DOWNSTREAM means: keep up with whoever needs me.
Let's total the orders per manager, reading from the joined dynamic table rather than from the base table.
CREATE OR REPLACE DYNAMIC TABLE DT_BY_MANAGER_T110
TARGET_LAG = DOWNSTREAM
WAREHOUSE = COMPUTE_WH
AS
SELECT MANAGER, COUNT(*) AS ORDERS, SUM(AMOUNT) AS TOTAL
FROM DT_JOINED_T110
GROUP BY MANAGER;| status |
|---|
| Dynamic table DT_BY_MANAGER_T110 successfully created. |
SELECT MANAGER, ORDERS, TOTAL FROM DT_BY_MANAGER_T110 ORDER BY MANAGER;| MANAGER | ORDERS | TOTAL |
|---|---|---|
| Eli | 2 | 100.00 |
| Nadia | 3 | 1350.00 |
| Sam | 2 | 385.50 |
A row per manager, with a count and a total. Nadia has the most, because the order we added earlier was hers.
And the catalog reports that lag literally. Same trick as before: run the SHOW, then read it.
SHOW DYNAMIC TABLES IN SCHEMA PUBLIC;SELECT "name", "target_lag", "refresh_mode"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "name" LIKE '%T110'
ORDER BY "name";| name | target_lag | refresh_mode |
|---|---|---|
| DT_BY_MANAGER_T110 | DOWNSTREAM | INCREMENTAL |
| DT_JOINED_T110 | 1 day | INCREMENTAL |
| DT_RANKED_T110 | 2 days | INCREMENTAL |
| DT_UNIONED_T110 | 1 day | INCREMENTAL |
DOWNSTREAM, in the same column that says 1 day for the others. Now let's add another order and refresh only the child.
INSERT INTO ORDERS_T110 (ORDER_ID, REGION, CUSTOMER, AMOUNT)
SELECT 8, 'south', 'Hana', 500.00;| number of rows inserted |
|---|
| 1 |
ALTER DYNAMIC TABLE DT_BY_MANAGER_T110 REFRESH;| dt_name | statistics | refreshed_dt_count | data_timestamp |
|---|---|---|---|
| DEMO_DB.PUBLIC.DT_BY_MANAGER_T110 | {"insertedRows":1,"copiedRows":2,"deletedRows":1} | 2 | 2026-09-28 18:26:22.126000-07:00 |
Look at refreshed_dt_count. We named one object and two were refreshed. The child could not answer correctly without its parent, so it pulled the parent along with it.
The statistics are more interesting here too. One row inserted, two copied, one deleted — which is what changing a group total looks like when you apply it as a change rather than recomputing it.
SELECT MANAGER, ORDERS, TOTAL FROM DT_BY_MANAGER_T110 ORDER BY MANAGER;| MANAGER | ORDERS | TOTAL |
|---|---|---|
| Eli | 2 | 100.00 |
| Nadia | 3 | 1350.00 |
| Sam | 3 | 885.50 |
Sam has gone up, because the order we added was in the south.
And now let's look at the parent, which we never touched.
SELECT COUNT(*) AS PARENT_ROWS, SUM(AMOUNT) AS PARENT_TOTAL FROM DT_JOINED_T110;| PARENT_ROWS | PARENT_TOTAL |
|---|---|
| 8 | 2335.50 |
SELECT (SELECT COUNT(*) FROM ORDERS_T110) AS BASE_ROWS,
(SELECT COUNT(*) FROM DT_JOINED_T110) AS PARENT_ROWS,
(SELECT SUM(ORDERS) FROM DT_BY_MANAGER_T110) AS ORDERS_THE_CHILD_COUNTS;| BASE_ROWS | PARENT_ROWS | ORDERS_THE_CHILD_COUNTS |
|---|---|---|
| 8 | 8 | 8 |
The base table, the parent dynamic table and the total the child counts all agree. One refresh, asked for in one place, and the whole chain moved.
What happens when we drop a table it depends on?
The joined dynamic table reads from two tables. Let's take one of them away.
DROP TABLE REGIONS_T110;| status |
|---|
| REGIONS_T110 successfully dropped. |
Now let's see what is left in the catalog.
SELECT TABLE_NAME, TABLE_TYPE
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC' AND RIGHT(TABLE_NAME, 5) = '_T110'
ORDER BY TABLE_NAME;| TABLE_NAME | TABLE_TYPE |
|---|---|
| DT_BY_MANAGER_T110 | BASE TABLE |
| DT_JOINED_T110 | BASE TABLE |
| DT_RANKED_T110 | BASE TABLE |
| DT_UNIONED_T110 | BASE TABLE |
| ORDERS_T110 | BASE TABLE |
All four dynamic tables are still listed, and so is ORDERS_T110. The table we dropped is simply gone from the list. Dropping a source does not drop the objects built on it.
So can we still read the one whose source has gone?
SELECT COUNT(*) AS ROWS_STILL_READABLE FROM DT_JOINED_T110;| ROWS_STILL_READABLE |
|---|
| 8 |
We can. It is holding rows, and rows do not need the source table to be read back.
Can we refresh it, though?
ALTER DYNAMIC TABLE DT_JOINED_T110 REFRESH;002742 (01000): SQL compilation error: Failed to refresh dynamic table with refresh_trigger MANUAL at data_timestamp 1790645187482 because of the error: SQL compilation error: Target table failed to refresh: SQL compilation error: Failure during expansion of view 'DT_JOINED_T110': SQL compilation error: Object 'DEMO_DB.PUBLIC.REGIONS_T110' does not exist or not authorized. Your primary role ACCOUNTADMIN must have at least one privilege granted on TABLE DEMO_DB.PUBLIC.REGIONS_T110. (Note: the dynamic table runs as owner role 'ACCOUNTADMIN'. Ensure this role has access to all referenced objects. See https://docs.snowflake.com/en/user-guide/dynamic-tables/troubleshoot-permissions for details.)
No. Failed to refresh dynamic table, and the reason underneath it is that the query cannot be expanded any more. The rows it already has are fine. It just cannot move.
Let's put the table back and try again.
UNDROP TABLE REGIONS_T110;| status |
|---|
| Table REGIONS_T110 successfully restored. |
ALTER DYNAMIC TABLE DT_JOINED_T110 REFRESH;| dt_name | statistics | refreshed_dt_count | data_timestamp |
|---|---|---|---|
| DEMO_DB.PUBLIC.DT_JOINED_T110 | No new data | 0 | 2026-09-28 18:26:28.195000-07:00 |
This time it works, and the statistics column says No new data with nothing refreshed. Nothing changed while the table was away, so there was nothing to do.
SELECT ORDER_ID, REGION, MANAGER, AMOUNT FROM DT_JOINED_T110 ORDER BY ORDER_ID;| ORDER_ID | REGION | MANAGER | AMOUNT |
|---|---|---|---|
| 1 | north | Nadia | 100.00 |
| 2 | north | Nadia | 250.00 |
| 3 | south | Sam | 75.50 |
| 4 | south | Sam | 310.00 |
| 5 | east | Eli | 40.00 |
| 6 | east | Eli | 60.00 |
| 7 | north | Nadia | 1000.00 |
| 8 | south | Sam | 500.00 |
Every order is there, each with its manager. The dynamic table kept what it had the whole time.
One last thing: let's tidy up
A dynamic table is dropped the same way as anything else, and the child goes first because it reads from the parent.
-- Put the schema back the way we found it.
DROP DYNAMIC TABLE IF EXISTS DT_BY_MANAGER_T110;
DROP DYNAMIC TABLE IF EXISTS DT_JOINED_T110;
DROP DYNAMIC TABLE IF EXISTS DT_RANKED_T110;
DROP DYNAMIC TABLE IF EXISTS DT_UNIONED_T110;
DROP TABLE IF EXISTS ORDERS_T110;
DROP TABLE IF EXISTS REGIONS_T110;SELECT CURRENT_DATABASE() AS THE_DATABASE,
CURRENT_SCHEMA() AS THE_SCHEMA,
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES
WHERE RIGHT(TABLE_NAME, 5) = '_T110') AS PROBE_OBJECTS_LEFT,
(SELECT COUNT(*) FROM CUSTOMERS) AS DEMO_DB_IS_READABLE;| THE_DATABASE | THE_SCHEMA | PROBE_OBJECTS_LEFT | DEMO_DB_IS_READABLE |
|---|---|---|---|
| DEMO_DB | PUBLIC | 0 | 10 |
No probe objects left, and the demo database still reads. Back where we started.
Key points
- A dynamic table takes query shapes a materialized view refuses. The join and the window function from Episode 109 were both accepted here.
- You declare a
TARGET_LAG, which is how stale the answer may be. You never write a refresh. - It is populated when it is created, because
initialize = ON_CREATEis the default. Nothing had to be refreshed before the first read. INFORMATION_SCHEMA.TABLEScalls it aBASE TABLEand gives it aROW_COUNT.IS_INSERTABLE_INTOofNOis the only column there that gives it away.INSERT,UPDATE,DELETEandTRUNCATEare all refused with the same error, only the verb changing.refresh_mode = AUTOis what you ask for by saying nothing.INCREMENTALis what Snowflake chose, andSHOW DYNAMIC TABLESreports both.- It is allowed to be out of date, and you can watch it happen: the base table moved on and the dynamic table did not.
ALTER DYNAMIC TABLE ... REFRESHreports what it changed, row by row, in astatisticscolumn.SUSPENDstops the refreshing and not the reading. A suspended dynamic table still hands back everything it holds.TARGET_LAG = DOWNSTREAMon a child means refreshing the child pulls its parent along with it, andrefreshed_dt_countsays so.- Drop a source table and the dynamic table keeps its rows and stops being able to refresh.
UNDROPthe source and it moves again. - Reach for one when the query is too complicated for a materialized view and an answer from an hour or a day ago is good enough.
Episode 111 — sequences. A sequence promises unique numbers and increasing numbers. It delivers one of those two, and SHOW SEQUENCES has a column that admits which.
Every query and every result grid on this page was captured from a live Snowflake account (version 10.34.101) running the demo script for this episode. The _T110 objects are created and dropped by the scripts above. Nothing on this page is timed, no refresh duration is quoted, and no performance claims are made anywhere in this series: the TARGET_LAG is a day throughout so that nothing waits on a clock, and every refresh is asked for by hand. Where the spoken episode and its own captured output disagree, this post follows the captures and says so. Dynamic table behaviour follows the Snowflake dynamic tables documentation.



No comments:
Post a Comment
Note: Only a member of this blog may post a comment.