Bird
Raised Fist0
Snowflakecloud~5 mins

Time Travel retention periods in Snowflake - Commands & Configuration

Choose your learning style10 modes available
Introduction
Sometimes you need to see or restore data as it was in the past. Time Travel in Snowflake lets you do this by keeping past versions of your data for a set time. Retention periods control how long these past versions are kept.
When you accidentally delete or change data and want to recover it within a few days.
When you want to audit changes made to your tables over the last few days.
When you want to clone a table as it was at a specific time in the past.
When you want to keep historical data snapshots for a short period without manual backups.
When you want to comply with data retention policies that require short-term data recovery.
Commands
This command sets the Time Travel retention period for 'my_table' to 3 days, meaning you can access past data versions up to 3 days old.
Terminal
ALTER TABLE my_table SET DATA_RETENTION_TIME_IN_DAYS = 3;
Expected OutputExpected
ALTER TABLE
This command queries 'my_table' as it was 3600 seconds (1 hour) ago, using Time Travel to see past data.
Terminal
SELECT * FROM my_table AT (OFFSET => -3600);
Expected OutputExpected
ID | NAME 1 | Alice 2 | Bob
This command shows the current Time Travel retention period setting for 'my_table'.
Terminal
SHOW PARAMETERS LIKE 'DATA_RETENTION_TIME_IN_DAYS' IN TABLE my_table;
Expected OutputExpected
name | value | level DATA_RETENTION_TIME_IN_DAYS | 3 | TABLE
Key Concept

If you remember nothing else from this pattern, remember: Time Travel retention periods control how long you can access past versions of your data for recovery or auditing.

Common Mistakes
Setting the retention period longer than your Snowflake edition allows.
Snowflake editions have maximum allowed retention periods; exceeding them causes errors.
Check your Snowflake edition limits and set retention periods within allowed ranges.
Trying to query past data beyond the retention period.
Data older than the retention period is permanently removed and cannot be accessed.
Only query past data within the retention period you have set.
Not setting retention period explicitly and assuming default is long.
Default retention is usually 1 day; you might lose data history sooner than expected.
Explicitly set retention period to match your recovery needs.
Summary
Use ALTER TABLE to set the Time Travel retention period in days.
Query past data using SELECT with AT clause and OFFSET in seconds.
Check current retention settings with SHOW PARAMETERS command.

Practice

(1/5)
1. What does the Time Travel retention period in Snowflake control?
easy
A. How long you can access previous versions of data
B. How long data is stored in the cloud
C. The speed of query execution
D. The number of users who can access a table

Solution

  1. Step 1: Understand Time Travel feature

    Time Travel allows you to see and restore past versions of your data.
  2. Step 2: Identify what retention period controls

    The retention period sets how many days you can access these past versions.
  3. Final Answer:

    How long you can access previous versions of data -> Option A
  4. Quick Check:

    Retention period = access duration for past data [OK]
Hint: Retention period means how long past data is accessible [OK]
Common Mistakes:
  • Confusing retention with storage duration
  • Thinking it controls query speed
  • Assuming it limits user access
2. Which SQL command correctly sets the Time Travel retention period to 7 days for a table named sales_data?
easy
A. ALTER TABLE sales_data SET RETENTION_DAYS = 7;
B. ALTER TABLE sales_data SET DATA_RETENTION_TIME_IN_DAYS = 7;
C. UPDATE TABLE sales_data SET DATA_RETENTION_TIME_IN_DAYS = 7;
D. ALTER TABLE sales_data DATA_RETENTION = 7;

Solution

  1. Step 1: Recall correct syntax for setting retention

    The correct command uses ALTER TABLE with SET DATA_RETENTION_TIME_IN_DAYS.
  2. Step 2: Match syntax with options

    ALTER TABLE sales_data SET DATA_RETENTION_TIME_IN_DAYS = 7; matches the exact syntax; others use incorrect keywords or commands.
  3. Final Answer:

    ALTER TABLE sales_data SET DATA_RETENTION_TIME_IN_DAYS = 7; -> Option B
  4. Quick Check:

    Use ALTER TABLE ... SET DATA_RETENTION_TIME_IN_DAYS [OK]
Hint: Use ALTER TABLE ... SET DATA_RETENTION_TIME_IN_DAYS [OK]
Common Mistakes:
  • Using UPDATE instead of ALTER TABLE
  • Wrong keyword like RETENTION_DAYS
  • Missing SET keyword
3. Given a table with a Time Travel retention period of 3 days, what happens if you try to query data from 5 days ago using Time Travel?
medium
A. You get an error because data older than 3 days is not available
B. You get the data from 5 days ago without issues
C. The query runs but returns empty results
D. The retention period automatically extends to 5 days

Solution

  1. Step 1: Understand retention period limit

    Retention period limits how far back you can access data versions.
  2. Step 2: Apply to 5 days query with 3 days retention

    Since 5 days is beyond 3 days retention, data is unavailable and causes an error.
  3. Final Answer:

    You get an error because data older than 3 days is not available -> Option A
  4. Quick Check:

    Query beyond retention period = error [OK]
Hint: Cannot access data older than retention days [OK]
Common Mistakes:
  • Assuming data is always available
  • Thinking query returns empty instead of error
  • Believing retention auto-extends
4. You tried to set the Time Travel retention period to 100 days on a table, but Snowflake returned an error. What is the most likely cause?
medium
A. You need to restart the Snowflake service
B. Syntax error in the ALTER TABLE command
C. Table does not support Time Travel
D. Retention period exceeds the maximum allowed limit

Solution

  1. Step 1: Know Snowflake retention limits

    Snowflake limits Time Travel retention to a maximum (usually 1 to 90 days depending on edition).
  2. Step 2: Check if 100 days exceeds limit

    100 days is beyond typical max, causing an error.
  3. Final Answer:

    Retention period exceeds the maximum allowed limit -> Option D
  4. Quick Check:

    Retention > max limit causes error [OK]
Hint: Check max retention days allowed before setting [OK]
Common Mistakes:
  • Assuming syntax error without checking limits
  • Thinking table lacks Time Travel support
  • Believing service restart fixes retention errors
5. A company wants to keep Time Travel data for 14 days but minimize storage costs. Which approach best balances these needs?
hard
A. Set DATA_RETENTION_TIME_IN_DAYS to 30 to avoid data loss
B. Set DATA_RETENTION_TIME_IN_DAYS to 1 and rely on backups for older data
C. Set DATA_RETENTION_TIME_IN_DAYS to 14 and regularly purge old data
D. Disable Time Travel and keep manual snapshots

Solution

  1. Step 1: Understand retention vs storage cost

    Longer retention means more storage cost; shorter retention saves cost but limits recovery.
  2. Step 2: Evaluate options for 14-day retention and cost balance

    Setting retention to 14 days meets recovery needs; purging old data helps control storage.
  3. Final Answer:

    Set DATA_RETENTION_TIME_IN_DAYS to 14 and regularly purge old data -> Option C
  4. Quick Check:

    Retention matches need + purge controls cost [OK]
Hint: Match retention days to need, purge to save cost [OK]
Common Mistakes:
  • Setting retention too low losing data
  • Setting retention too high increasing cost
  • Disabling Time Travel losing recovery benefits
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard