What you will be able to do
- Clone a table, schema or database as it was at a past point using AT or BEFORE with TIMESTAMP, OFFSET or STATEMENT
- Validate a change in an isolated clone and promote it with SWAP WITH
- Roll back a drop with UNDROP, or a bad change with a point-in-time clone, and know when self-service recovery is no longer possible
- Work around point-in-time database clones that fail because of child-table retention
1.Cloning a past state with AT | BEFORE
Time Travel extends cloning to the past. Within an object's data retention period, you can clone entire tables, schemas and databases as they were at, or just before, a chosen point. You add the AT | BEFORE clause right after the source name in CREATE … CLONE, and you pin the point with one of three parameters:
| Parameter | What it identifies | Watch out for |
|---|---|---|
| TIMESTAMP => timestamp | An exact date and time | Without an explicit cast, the value is treated as UTC (equivalent to TIMESTAMP_NTZ) |
| OFFSET => time_difference | Seconds back from the current time, written -N | N can be an arithmetic expression such as -30*60 |
| STATEMENT => id | The query ID of a DML, TCL or SELECT statement | The query must have run within the last 14 days |
CREATE SCHEMA restored_schema CLONE my_schema AT(OFFSET => -3600);AT includes the point you name. BEFORE stops just short of it. With a statement ID, BEFORE returns the data up to, but not including, the changes that statement made. That is exactly the state you want when one bad statement needs undoing.
A point-in-time clone does not rebuild everything from the past. As the prediction showed, user tasks are dropped from timestamp clones. Internal stages are not cloned when using Time Travel, and child objects that didn't exist at the chosen point are skipped. If the source itself didn't exist at that point, the statement returns an error. Name and structure come from the chosen point, but other metadata such as comments and clustering keys comes from the source as it is now.
Checkpoint 1 of 7· Check yourself
An engineer wants to clone a table as it was just before a bad UPDATE that ran three weeks ago, which is still inside the table's retention period. BEFORE(STATEMENT => '<query_id>') returns "statement not found". What should they do?
STATEMENT only accepts query IDs from the last 14 days. The docs' workaround is to use the query's timestamp instead.
“The query ID must reference a query that has been executed within the last 14 days.”Source: docs.snowflake.com
2.Validating changes in a clone, then promoting with SWAP WITH
Cloning, Time Travel and swapping fit together as a release workflow. Clone production, apply the change to the clone, check it, then make the checked version the live one. A clone is a good place for validation because it is writable and independent: migration scripts can run end to end and production never sees them. Nothing in the clone starts on its own. Tasks and alerts arrive suspended, so you can resume just the tasks you want to test with ALTER TASK … RESUME. The docs don't describe a specific test harness. Validation means whatever queries and task runs you choose to execute against the clone.
Promotion is done with a swap, not a copy. ALTER SCHEMA … SWAP WITH swaps all objects and metadata, including identifiers, between two schemas. It is effectively a rename of both schemas in a single operation. For a single table, ALTER TABLE … SWAP WITH renames two tables in one transaction. After the swap, the old production version still exists under the other name. If the release goes wrong, swapping again puts it back.
ALTER SCHEMA [ IF EXISTS ] <name> SWAP WITH <target_schema_name>Checkpoint 2 of 7· Exam question
Six weeks after a schema was cloned for regression testing, the clone's table sizes in `TABLE_STORAGE_METRICS` have grown even though the original schema's size stayed flat. Which explanation matches how Zero-Copy Cloning charges for storage over time?
Correct answer: B — The clone and source initially share the same micro-partitions, and new storage is only allocated once DML against the clone rewrites or adds micro-partitions.
- A. Cloning does not copy micro-partitions into new physical storage at creation time; that would make cloning as slow and storage-heavy as a full copy, which defeats the purpose of zero-copy cloning.
- B. This matches copy-on-write behavior: the clone shares the source's micro-partitions until DML on the clone rewrites or adds partitions, which is exactly why the clone's reported size grows independently over six weeks of regression testing activity.
- C. `TABLE_STORAGE_METRICS` reflects real storage consumption, not a double-counting artifact; growth in the clone's reported size corresponds to genuine new micro-partitions created by writes against the clone.
- D. Clones do not receive a separate fixed storage quota, and Time Travel retention accruing on its own does not consume additional storage the way new or modified micro-partitions from DML do.
Checkpoint 3 of 7· Check yourself
A team validates a migration in schema SALES_DEV, then runs ALTER SCHEMA SALES_DEV SWAP WITH SALES. Which statement is accurate?
SWAP WITH exchanges everything, including identifiers and the privileges on the schemas and their objects, as one rename of both schemas.
“Also swaps all access control privileges granted on the schemas and objects they contain.”Source: docs.snowflake.com
3.Rolling back: UNDROP, point-in-time clones, and where recovery ends
Rolling back a dropped object takes one command. UNDROP restores a dropped table, schema or database to its state just before the DROP. The object is restored in place, not created as a new one. You need OWNERSHIP of the object, plus the CREATE privilege for that object type in the database or schema it returns to. If an object with the same name already exists, UNDROP fails, so rename the existing object first.
UNDROP TABLE mytable; UNDROP SCHEMA myschema; UNDROP DATABASE mydatabase;Checkpoint 4 of 7· Put it in order
Table loaddata1 was dropped and recreated twice, so there is a current version and two dropped versions. Put the steps that restore both dropped versions in order.
- 1.Rename the current loaddata1 to loaddata3
- 2.Rename that restored loaddata1 to loaddata2
- 3.UNDROP TABLE loaddata1 to restore the most recently dropped version
- 4.UNDROP TABLE loaddata1 again to restore the first dropped version
UNDROP restores the most recent dropped version and fails if the name is taken. Each restore therefore has to free the name first.
“First, the current table with the same name is renamed to loaddata3.”Source: docs.snowflake.com
A bad UPDATE or DELETE doesn't drop anything, so UNDROP can't help. Instead, clone the object as it was before the change, with BEFORE(STATEMENT => …) or AT(TIMESTAMP => …). Then repair from the clone or swap it in.
CREATE TABLE restored_table CLONE my_table AT(TIMESTAMP => 'Wed, 26 Jun 2024 01:01:00 +0300'::timestamp_tz);Both methods stop working when the retention period ends. The standard period is 1 day. On Enterprise Edition and higher, permanent objects can be set anywhere from 0 to 90 days. Transient objects, and temporary tables, can only be 0 or 1. Once the period ends, history moves to Fail-safe and can no longer be queried, cloned or undropped. A permanent table in Fail-safe (7 days) can be recovered only by Snowflake. A transient or temporary table has no Fail-safe and is purged. With retention set to 0, a dropped object can't be restored at all. Check retention before you count on a rollback:
SHOW TABLES
->> SELECT "name", "retention_time"
FROM $1
WHERE "name" IN ('MY_TABLE1', 'MY_TABLE2');| Situation | Rollback | Result |
|---|---|---|
| Table, schema or database dropped, still within retention | UNDROP <object> | Restored in place to its state just before the DROP |
| Bad DML, still within retention | CREATE … CLONE with AT | BEFORE | A new object holding the earlier state |
| Retention period has ended | None (data is in Fail-safe) | Can't query, clone or restore historical data |
| Retention set to 0 | None | A dropped object can't be restored |
Checkpoint 5 of 7· Exam question
On a Snowflake account running Enterprise Edition, what is the maximum value that can be configured for `DATA_RETENTION_TIME_IN_DAYS` on a permanent table?
Correct answer: C — 90 days
- A. 0 days is a valid setting that effectively disables Time Travel for the object, but it is the minimum, not the maximum, retention value available.
- B. 1 day is the default retention period across all editions, but Enterprise Edition allows configuring a longer period than this default.
- C. Enterprise Edition (and higher) permits `DATA_RETENTION_TIME_IN_DAYS` to be set anywhere from 0 up to 90 days for permanent objects, which is the correct maximum.
- D. 365 days exceeds what any Snowflake edition supports for `DATA_RETENTION_TIME_IN_DAYS`; the documented ceiling for permanent objects is 90 days.
Checkpoint 6 of 7· Check yourself
A permanent table with a 1-day retention period was dropped three days ago. What can the team do?
Time Travel ended after one day. The table is now in Fail-safe, which users can't access themselves.
“In Fail-safe (7 days), a dropped table can be recovered, but only by Snowflake.”Source: docs.snowflake.com
4.When a point-in-time database clone fails
Rolling back a whole database or schema with a Time Travel clone can fail even when the container's own retention covers the target time. Each child table keeps its own retention period. A child with a shorter period loses its history before its parent does. Say database db1 keeps 7 days and its table t1 keeps 1 day. Cloning db1 as of 12 hours ago works. Cloning it as of two days ago fails, because t1's history from then is gone. The clone also fails if a pipe with AUTO_INGEST = TRUE has been recreated or dropped since the chosen point, or if the source contains hybrid tables and IGNORE HYBRID TABLES isn't specified.
For the retention problem, the fix is IGNORE TABLES WITH INSUFFICIENT DATA RETENTION. It skips any table whose history no longer reaches the chosen time, and clones everything else.
CREATE DATABASE restored_db CLONE my_db AT(TIMESTAMP => DATEADD(days, -4, current_timestamp)::timestamp_tz) IGNORE TABLES WITH INSUFFICIENT DATA RETENTION;Checkpoint 7 of 7· Check yourself
A database has 30-day retention, but some of its transient tables keep only 1 day. Cloning the database as of five days ago fails. Which change lets the clone succeed?
The transient tables have no history from five days ago. This clause skips them so the rest of the database can be cloned.
“The parameter skips tables that no longer have historical data available in Time Travel at the time specified for the cloning operation.”Source: docs.snowflake.com
Sources2
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.Once Time Travel retention has passed, you can still UNDROP a permanent table yourself during its 7 days in Fail-safe.Why is that wrong?
Users can't use Fail-safe themselves. Only Snowflake can recover data from it.
Covered in Rolling back: UNDROP, point-in-time clones, and where recovery ends
2.UNDROP replaces any table that currently has the same name.Why is that wrong?
UNDROP fails if an object with that name exists. You must rename the existing object first.
Covered in Rolling back: UNDROP, point-in-time clones, and where recovery ends
3.A schema cloned AT a timestamp contains everything a current clone would, including its user tasks.Why is that wrong?
User tasks are not cloned when the clone uses a timestamp, even though a current clone of the same schema would include them.
Covered in Cloning a past state with AT | BEFORE
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Create clones of entire tables, schemas, and databases at or before specific points in the past.”
↩︎ Cloning a past state with AT | BEFORE“selects historical data from a table up to, but not including any changes made by the specified statement”
↩︎ Cloning a past state with AT | BEFORE“Calling UNDROP restores the object to its most recent state before the DROP command was issued.”
↩︎ Rolling back: UNDROP, point-in-time clones, and where recovery ends“Restoring a dropped object restores the object in place (that is, it does not create a new object).”
↩︎ Rolling back: UNDROP, point-in-time clones, and where recovery ends“For permanent databases, schemas, and tables, the retention period can be set to any value from 0 up to 90 days.”
↩︎ Rolling back: UNDROP, point-in-time clones, and where recovery ends“When an object with no retention period is dropped, you will not be able to restore the object.”
↩︎ Rolling back: UNDROP, point-in-time clones, and where recovery ends“If an object with the same name already exists, UNDROP fails.”
↩︎ Exam trap 2“First, the current table with the same name is renamed to loaddata3.”
↩︎ Checkpoint - 2.
“If the source object didn’t exist at the time/point set in the AT | BEFORE clause, an error is returned.”
↩︎ Cloning a past state with AT | BEFORE“The tasks can be resumed individually (using ALTER TASK … RESUME).”
↩︎ Validating changes in a clone, then promoting with SWAP WITH“the historical data for table t1 at that point is no longer available”
↩︎ When a point-in-time database clone fails“The parameter skips tables that no longer have historical data available in Time Travel at the time specified for the cloning operation.”
↩︎ Checkpoint - 3.
“Specifies the difference in seconds from the current time to use for Time Travel”
↩︎ Cloning a past state with AT | BEFORE“User tasks in a database or schema are not cloned when using CREATE SCHEMA … TIMESTAMP.”
↩︎ Exam trap 3“User tasks in a database or schema are not cloned when using CREATE SCHEMA … TIMESTAMP.”
↩︎ Prediction“The query ID must reference a query that has been executed within the last 14 days.”
↩︎ Checkpoint - 4.
“Swaps all objects (tables, views, etc.) and metadata, including identifiers, between the two specified schemas.”
↩︎ Validating changes in a clone, then promoting with SWAP WITH“SWAP WITH essentially performs a rename of both schemas as a single operation.”
↩︎ Validating changes in a clone, then promoting with SWAP WITH“Also swaps all access control privileges granted on the schemas and objects they contain.”
↩︎ Checkpoint - 5.
“Swap renames two tables in a single transaction.”
↩︎ Validating changes in a clone, then promoting with SWAP WITH - 6.
“A transient or temporary table has no Fail-safe, so it is purged when it moves out of Time Travel.”
↩︎ Rolling back: UNDROP, point-in-time clones, and where recovery ends“In Fail-safe (7 days), a dropped table can be recovered, but only by Snowflake.”
↩︎ Exam trap 1“In Fail-safe (7 days), a dropped table can be recovered, but only by Snowflake.”
↩︎ Checkpoint