Why this works: immutable micro-partitions
Remember from lesson 2: micro-partitions are never edited. An UPDATE writes new micro-partitions with the changed rows and marks the old ones as no longer current. Snowflake keeps those old ones for the table's retention period, so the past is still there to read.
๐Current data
What every query sees
โชTime Travel
1 day default, up to 90 (Enterprise). You can query, clone, UNDROP.
๐Fail-safe
7 more days, permanent tables only. Snowflake Support only.
๐๏ธGone
Storage is freed
The classic accident: UPDATE without WHERE
We continue with ShopKart's orders table from lesson 4. First, give it a week of history:
USE SCHEMA shopkart.raw;
-- Keep 7 days of history for orders (Standard edition: max 1 day; Enterprise: up to 90)
ALTER TABLE orders SET DATA_RETENTION_TIME_IN_DAYS = 7;
SELECT status, COUNT(*) AS orders FROM orders GROUP BY status ORDER BY orders DESC;| STATUS | ORDERS |
|---|---|
| DELIVERED | 4145 |
| PLACED | 525 |
| CANCELLED | 445 |
| RETURNED | 200 |
Now someone means to cancel one order and forgets the WHERE:
-- ๐ฑ Someone forgets the WHERE clause
UPDATE orders SET status = 'CANCELLED';
SET bad_query = LAST_QUERY_ID(); -- remember which statement did it
SELECT status, COUNT(*) AS orders FROM orders GROUP BY status;| number of rows updated |
|---|
| 5315 |
| STATUS | ORDERS |
|---|---|
| CANCELLED | 5315 |
Every single order is now cancelled. On many databases this means restoring last night's backup. Here:
-- Time Travel: the table exactly as it was before that statement
SELECT status, COUNT(*) AS orders
FROM orders BEFORE (STATEMENT => $bad_query)
GROUP BY status
ORDER BY orders DESC;| STATUS | ORDERS |
|---|---|
| DELIVERED | 4145 |
| PLACED | 525 |
| CANCELLED | 445 |
| RETURNED | 200 |
The correct data, exactly as it was one statement ago. Now put it back:
-- Fix it: clone the old version, then swap it in (one atomic step)
CREATE OR REPLACE TABLE orders_restored CLONE orders BEFORE (STATEMENT => $bad_query);
ALTER TABLE orders SWAP WITH orders_restored;
DROP TABLE orders_restored; -- this is now the broken table
SELECT status, COUNT(*) AS orders FROM orders GROUP BY status ORDER BY orders DESC;| STATUS | ORDERS |
|---|---|
| DELIVERED | 4145 |
| PLACED | 525 |
| CANCELLED | 445 |
| RETURNED | 200 |
Three ways to point at the past
| Clause | Means | Best when |
|---|---|---|
| AT (TIMESTAMP => ts) | As it was at that moment | You know roughly when things were right |
| AT (OFFSET => -seconds) | As it was N seconds ago | Quick checks: -60*60 = an hour ago |
| BEFORE (STATEMENT => query_id) | Just before that statement ran | You know exactly which query broke it |
SET before_change = CURRENT_TIMESTAMP();
SELECT SYSTEM$WAIT(2);
DELETE FROM products WHERE category = 'Home';
SELECT COUNT(*) AS products_now FROM products;
-- The table as it was at a moment in time...
SELECT COUNT(*) AS products_then FROM products AT (TIMESTAMP => $before_change);
-- ...or N seconds ago
SELECT COUNT(*) AS products_10s_ago FROM products AT (OFFSET => -10);| PRODUCTS_NOW |
|---|
| 8 |
| PRODUCTS_THEN |
|---|
| 12 |
| PRODUCTS_10S_AGO |
|---|
| 12 |
You don't have to restore a whole table. Here we bring back only the four deleted rows:
-- Put just the deleted rows back
INSERT INTO products
SELECT * FROM products AT (TIMESTAMP => $before_change) WHERE category = 'Home';
SELECT category, COUNT(*) AS products FROM products GROUP BY category ORDER BY category;| CATEGORY | PRODUCTS |
|---|---|
| Electronics | 4 |
| Fashion | 4 |
| Home | 4 |
Time Travel has limits
-- Orders an hour ago? (Remember: we swapped in a clone a minute ago)
SELECT COUNT(*) FROM orders AT (OFFSET => -60*60);000707 (02000): Time travel data is not available for table ORDERS. The requested time is
either beyond the allowed time travel period or before the object creation time.Our orders table is now the clone we swapped in, created a minute earlier, so its history starts there. You also can't go further back than the retention period. If you'll need old versions for longer (audits, month-end reports), don't rely on Time Travel: keep snapshots or history tables on purpose.
UNDROP
DROP TABLE customers; -- oops, wrong table
SELECT COUNT(*) FROM customers;002003 (42S02): SQL compilation error: Table 'SHOPKART.RAW.CUSTOMERS' does not exist or not authorized.SHOW TABLES HISTORY LIKE 'CUSTOMERS'; -- dropped tables are still listed here
UNDROP TABLE customers;
SELECT COUNT(*) AS customers FROM customers;| name | rows | dropped_on | retention_time |
|---|---|---|---|
| CUSTOMERS | 200 | 2026-11-22 01:24:40 -08:00 | 1 |
| status |
|---|
| Table CUSTOMERS successfully restored. |
| CUSTOMERS |
|---|
| 200 |
All 200 customers are back. UNDROP SCHEMA and UNDROP DATABASE work the same way. If you already created a new table with the same name, rename it first, or UNDROP fails.
Fail-safe: the emergency backup you can't touch
When Time Travel ends, permanent tables get 7 more days in Fail-safe. You can't query it or restore from it yourself; only Snowflake Support can recover data from it, for real disasters. Transient and temporary tables have no Fail-safe, which is exactly why they're cheaper (lesson 3).
| Table type | Time Travel | Fail-safe |
|---|---|---|
| Permanent (Standard edition) | 0โ1 day | 7 days |
| Permanent (Enterprise+) | 0โ90 days | 7 days |
| Transient | 0โ1 day | None |
| Temporary | 0โ1 day | None |
Zero-copy cloning
CLONE makes a copy of a table, schema or whole database by copying only metadata: the new object points at the same micro-partitions. No data is copied, so it's fast and free at first.
-- A full copy of ShopKart for testing: seconds, and no extra storage at first
CREATE OR REPLACE DATABASE shopkart_dev CLONE shopkart;
-- Change the dev copy freely...
DELETE FROM shopkart_dev.raw.orders WHERE status = 'CANCELLED';
-- ...production is untouched
SELECT 'prod' AS env, COUNT(*) AS orders FROM shopkart.raw.orders
UNION ALL
SELECT 'dev', COUNT(*) FROM shopkart_dev.raw.orders;| number of rows deleted |
|---|
| 445 |
| ENV | ORDERS |
|---|---|
| prod | 5315 |
| dev | 4870 |
The whole ShopKart database (every schema, table and file format) was cloned in 2.6 seconds, according to our query history. One thing did not come along: we checked, and the internal stage landing doesn't exist in the clone, because internal named stages aren't cloned. The 445 rows we deleted in dev are still in prod. From now on, only the micro-partitions that change in either copy take new storage.
| Clone use | Example |
|---|---|
| Dev and test environments | Clone prod every morning; test new pipelines on real data |
| Safe experiments | Clone a table before a risky migration; drop the clone if it worked |
| Point-in-time copies | CREATE TABLE orders_month_end CLONE orders AT (TIMESTAMP => ...) |
| Undo with SWAP | Like we did with the bad UPDATE |
๐ฏ Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1What is Time Travel and how do you use it?Fresher+
Q2Time Travel vs Fail-safe?Fresher+
Q3What is zero-copy cloning and how does it work?1โ3 yrs+
Q4A developer ran DELETE without a WHERE clause on a production table an hour ago. Walk me through recovery.1โ3 yrs+
Q5How do Time Travel and Fail-safe affect cost, and how do you control it?3+ yrs+
Q6What should you watch out for when cloning?3+ yrs+
Key takeaways
- โSnowflake's undo button is built in: Time Travel and UNDROP.
- โSave the query ID of risky statements; BEFORE(STATEMENT) is the most precise recovery.
- โClones make test copies of production instantly and cheaply.
- โHistory costs storage, so tune retention and use transient tables where it makes sense.
Frequently asked questions
What is Time Travel in Snowflake?
The ability to query, clone or restore data as it was at an earlier point, using AT or BEFORE with a timestamp, an offset in seconds or a query ID. It works for as many days as the table's DATA_RETENTION_TIME_IN_DAYS (1 by default, up to 90 on Enterprise).
What's the difference between Time Travel and Fail-safe?
Time Travel is self-service: you query or restore old data yourself during the retention period. Fail-safe is 7 more days after that, for permanent tables only, when only Snowflake Support can recover data, as a last resort for disasters. You can't query Fail-safe data.
Does a zero-copy clone double my storage bill?
No. A clone shares the original's micro-partitions, so it costs nothing extra at first. You pay only for data that changes afterwards in either copy, because changed data is written to new micro-partitions.
Can I undrop a database or schema?
Yes. UNDROP works for tables, schemas and databases (and a few other objects) as long as they're still within their Time Travel retention period. If an object with the same name exists, rename it first.
Does longer retention cost more?
Yes: Snowflake keeps old micro-partitions for the whole Time Travel period plus 7 days of Fail-safe, and you pay storage for them. Tables that change a lot (rewritten every hour) can build up much more history storage than their current size. Use transient tables or shorter retention for data you can rebuild.
๐ง Quick check: Time Travel and cloning
1. Someone ran an UPDATE without WHERE. Which query shows the data just before it?
2. Maximum Time Travel on Enterprise edition for a permanent table?
3. Who can recover data from Fail-safe?
4. What does CREATE DATABASE dev CLONE prod copy?
5. After ALTER TABLE orders SWAP WITH orders_restored, orders' Time Travel history starts...
Checking your accessโฆ