UNDROP TABLE
Using the UNDROP TABLE statement, you can restore deleted tables, dynamic tables, and materialized views. Whether a deleted object can be restored depends on the table's data retention period.
Data Retention Period
Whether an object can be restored depends on the data retention period (data_retention_days). The default retention period in Lakehouse is 1 day (24 hours). You can adjust the retention period using the ALTER TABLE command; the valid range is 0–90 days.
Supported Object Types
UNDROP TABLE can restore the following types of objects:
| Deleted Object | Drop Command | Restore Command |
|---|---|---|
| Regular table (TABLE) | DROP TABLE | UNDROP TABLE |
| Dynamic table (DYNAMIC TABLE) | DROP DYNAMIC TABLE | UNDROP TABLE |
| Materialized view (MATERIALIZED VIEW) | DROP MATERIALIZED VIEW | UNDROP TABLE |
| Table Stream | DROP TABLE STREAM | UNDROP TABLE |
Syntax
Parameter Description
| Parameter | Description |
|---|---|
schema_name | Optional. Specifies the schema name. |
table_name | The name of the deleted table, dynamic table, or materialized view. |
Examples
Example 1: Restore a Table Immediately After Deletion
Example 2: Restore a Table After a Same-Name Table Was Created
If a table with the same name was created after the original was dropped, rename the new table first before restoring the old one:
Example 3: Restore a Dynamic Table
Example 4: Restore a Materialized View
Notes
-
Restore within the retention period: The restore operation must be performed within the
data_retention_daysretention period. Once the period expires, data is physically deleted and cannot be recovered. -
Same-name object conflict: Ensure no object with the same name exists before restoring. If one does, rename or drop it first.
-
Properties preserved after restore:
- Regular tables retain their original schema, data, and properties (including
data_retention_days,data_lifecycle, etc.) - Dynamic tables retain their original refresh configuration (REFRESH INTERVAL, VCLUSTER, etc.)
- Materialized views retain their original query definition
- Regular tables retain their original schema, data, and properties (including
-
Objects that cannot be restored: Regular views (VIEW), external tables (EXTERNAL TABLE), indexes, functions, connections, and similar objects cannot be restored after deletion.
Related Documentation
- DROP TABLE
- DROP DYNAMIC TABLE
- DROP MATERIALIZED VIEW
- Time Travel Query
- RESTORE TABLE
- Historical Data Rollback: Complete workflow for data recovery using Time Travel and UNDROP together
