Recovery starts with evidence, not a restore command
Time Travel lets you inspect retained earlier table data; recovery uses that evidence to repair the right object or records.
Your learning goal
Create the shared four-order fixture, distinguish reading history from restoring data, and describe an incident response before writing repair SQL.
Understand the idea
A concrete example
A developer deletes all west-region orders while trying to remove a cancelled order. Revenue drops, but new orders continue arriving. Restoring yesterday’s whole table could fix the missing rows and lose today’s legitimate orders at the same time.
| Concept | What it means |
|---|---|
| Incident | An unintended change with a known scope and time. |
| Recovery point | A historical state selected from evidence, not guesswork. |
| Time Travel read | A SELECT of retained historical data; current data is unchanged. |
| Repair | An explicit reviewed write or restoration of a dropped object. |
Remember: Keep the original evidence and an approved repair scope. Rehearse recovery before relying on it during an incident.
Explain it step by step · full theory
Learning objectives and prerequisites
Create the shared four-order fixture, distinguish reading history from restoring data, and describe an incident response before writing repair SQL.
Build on Modules 02–04: storage, table types, SELECT, DML and transactions. Module 13 explains why recovery must preserve valid business history. Use the first lesson’s isolated setup; examples name separate demonstration tables so the baseline ORDERS stays unchanged.
Why a successful SQL statement can still be a failure
A database checks whether SQL is valid and permitted; it cannot know that the business intended a narrower WHERE clause. A DELETE can finish successfully while removing the wrong orders. Monitoring should therefore reconcile business keys, counts and totals, not only task status.
Separate three questions: what changed, which changes were wrong, and what correct changes happened afterwards. Those answers determine whether to insert missing records, repair selected columns or restore an entire dropped object.
How history can exist without hourly full copies
A micro-partition is an immutable unit of Snowflake-managed table storage. Conceptually, table versions refer to sets of those units. Changes create replacement data rather than editing an old immutable unit in place; eligible old data remains available for historical reads.
Think of a document whose previous pages remain available while its current index points to revised pages. This is an analogy, not a claim that Snowflake saves one page per row or a complete copy after every statement. The diagrams use fictional partition letters. Actual partition sizes and rewrite choices are managed by Snowflake.
Choose the recovery mechanism
An uncommitted DML mistake in your own explicit transaction may be handled by ROLLBACK. A committed mistake needs retained history or another recovery source. UNDROP is for a removed object; it does not reverse an UPDATE on an existing table.
| Failure | First approach | Important boundary |
|---|---|---|
| Uncommitted DML | Review then ROLLBACK | Only the open transaction; coordinate the session |
| Committed DELETE/UPDATE | Inspect history then targeted DML | Do not overwrite valid later work |
| Dropped object | Inspect history then UNDROP | Retention, privileges and original namespace matter |
| Outside self-service history | Escalate recovery plan | Fail-safe is not user-queryable backup |
Set up once; keep a stable baseline
Use the four-row ORDERS table throughout the module. Each destructive demonstration first makes its own copy or clone. ORDERS must remain unchanged so later expected results remain meaningful. In a new worksheet, select L2_OBJECTS_LAB.M14_LAB and an authorized warehouse.
CREATE DATABASE IF NOT EXISTS does not grant access to an existing database. Ask an administrator for an isolated database/schema if you lack permissions. You need USAGE on the warehouse/database/schema, creation privileges for new objects, SELECT on source data and the relevant write privileges on repair targets; ownership of your own lab objects simplifies the exercise.
- Run setup once in a learning account.
- Confirm four distinct keys and a total of 500.
- Record your role, warehouse, database and schema.
- Keep intentional failures confined to the demonstration names.
- If an object already exists, inspect it or use a fresh lab name consistently.
Production decisions and common mistakes
Keep the original evidence and an approved repair scope. Rehearse recovery before relying on it during an incident.
Do not treat Time Travel as an unlimited audit archive or cross-region disaster-recovery plan. Retention is finite, and a clone in the same account is not geographic resilience.
Key takeaways
Recover only the approved missing orders, preserve 105 and other valid changes, then validate uniqueness and business totals. Keep a record of the incident query ID and the recovery decision.
Words used in this lesson
- Micro-partition
- Immutable managed storage unit; not a user-created file.
- Incident scope
- The objects, keys and columns affected by the mistake.
- Recovery point
- A chosen historical boundary.
- Reconciliation
- Checking repaired state against expected business facts.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Recovery starts with evidence, not a restore command
- 101 · west · 100
- 102 · east · 200
- 103 · west · 150
- 104 · east · 50
10:00 · healthy orders
Four known orders total 500. Keep this baseline as evidence; detecting a missing row requires a trusted expectation, not just a successful SELECT.
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
- 10:00 · healthy orders
Four known orders total 500. Keep this baseline as evidence; detecting a missing row requires a trusted expectation, not just a successful SELECT.
- Current orders: 101 · west · 100; 102 · east · 200; 103 · west · 150; 104 · east · 50
- 11:00 · historical state
A historical point identifies a table state. It is not a separately scheduled backup or a full copy created every hour; these times are teaching labels.
- Historical reference: 101 · 100; 102 · 200; 103 · 150; 104 · 50
- Current orders: 4 orders · 500
- 12:00 · accidental deletion
An incorrect west-region predicate removes orders 101 and 103. Current reads see two orders; eligible older data can still be read through Time Travel.
- Before DELETE: 101 · 100; 102 · 200; 103 · 150; 104 · 50
- After DELETE: 101 · deleted; 103 · deleted; 102 + 104 · 250
- Investigate before writing
Identify the offending query and inspect its pre-change state. A historical read does not restore anything; repair is a separate, reviewed write.
- Detect: Missing keys; Wrong regional total
- Inspect history: BEFORE incident ID; Confirm affected keys
- Repair plan: Preserve later valid work; Validate before commit
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.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- 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.
- 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. - 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; SQL has not been executed for this course. Use an authorized warehouse and role with access to L2_OBJECTS_LAB and CREATE SCHEMA/CREATE TABLE as needed. Run in M14_LAB, in one session with one writer, using autocommit unless a transaction is shown. Run CREATE once, never replace an existing production object. Standard Edition with one-day retention is sufficient for the main lab; longer retention and administrative monitoring have separate requirements.
Create the recovery sandbox
Definition: A reproducible baseline gives every later comparison a known meaning.
When to use: Before the first exercise; this creates only a new M14_LAB schema and fixture.
-- New isolated learning setup. Do not add OR REPLACE.
-- If Module 03 already created this database, omit CREATE DATABASE.
CREATE DATABASE IF NOT EXISTS L2_OBJECTS_LAB;
USE DATABASE L2_OBJECTS_LAB;
CREATE SCHEMA M14_LAB DATA_RETENTION_TIME_IN_DAYS=1;
USE SCHEMA M14_LAB;
-- Select an existing authorized learning warehouse in Snowsight.
ALTER SESSION SET TIMEZONE='UTC';
ALTER SESSION SET QUERY_TAG='learnsnowflake_m14';
CREATE TABLE ORDERS (
ORDER_ID NUMBER, REGION VARCHAR, AMOUNT NUMBER(10,2), STATUS VARCHAR
) DATA_RETENTION_TIME_IN_DAYS=1;
INSERT INTO ORDERS VALUES
(101,'west',100,'paid'), (102,'east',200,'paid'),
(103,'west',150,'paid'), (104,'east',50,'paid');
SELECT * FROM ORDERS ORDER BY ORDER_ID;
SELECT COUNT(*) AS ROWS_PRESENT, COUNT(DISTINCT ORDER_ID) AS UNIQUE_KEYS,
SUM(AMOUNT) AS TOTAL FROM ORDERS;What to expect and why
The ordered rows below total 500 with four unique keys. These values are calculated from the supplied input, not captured from a Snowflake account. A warehouse query consumes credits even for a small teaching example.
| ORDER_ID | REGION | AMOUNT | STATUS |
|---|---|---|---|
| 101 | west | 100.00 | paid |
| 102 | east | 200.00 | paid |
| 103 | west | 150.00 | paid |
| 104 | east | 50.00 | paid |
Confirm session context
Definition: Context determines which object an unqualified SQL name resolves to.
When to use: Before every incident simulation.
SELECT CURRENT_ROLE(), CURRENT_WAREHOUSE(), CURRENT_DATABASE(), CURRENT_SCHEMA();
SELECT ORDER_ID, COUNT(*) FROM ORDERS GROUP BY ORDER_ID HAVING COUNT(*) <> 1;What to expect and why
The second query should return no rows. Standard-table primary keys would not replace this duplicate check; the example does not rely on enforced uniqueness.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Orders 101 and 103 disappear, but 105 arrives after the incident. What must a correct recovery preserve?
Compare your reasoning
Recover only the approved missing orders, preserve 105 and other valid changes, then validate uniqueness and business totals. Keep a record of the incident query ID and the recovery decision.
Key takeaway
Keep the original evidence and an approved repair scope. Rehearse recovery before relying on it during an incident.
Connect this lesson to the learning path
Official sources and curriculum
Module 14 · See module scope
By Rohit Ray · Independent educational lesson · Explore this visual lab