Module 14 · Lesson 6 of 12Detailed study · about 26 min

UNDROP tables, schemas and databases safely

UNDROP restores an eligible dropped object into its original namespace; it is not a command to reverse changes inside an existing table.

Your learning goal

Use disposable objects to practise UNDROP, resolve a naming conflict without discarding new work and explain container restoration limits.

Understand the idea

A concrete example

A deployment drops DROP_DEMO and recreates an empty table with the same name. The replacement and dropped original are different objects. Preserve both until you know which data and grants should remain.

Key ideas in simple English
ConceptWhat it means
UNDROP TABLERestore a dropped table, not deleted rows in an active table.
Name conflictRename the current replacement before restoring the dropped name.
Container restorationDatabase and schema recovery restore eligible contents; inspect independently dropped children.
EligibilityRequired privileges, original namespace and retained history still apply.

Remember: Inspect history and preserve same-name replacements. Verify data, privileges and dependencies after restoration.

Explain it step by step · full theory

Learning objectives and prerequisites

Use disposable objects to practise UNDROP, resolve a naming conflict without discarding new work and explain container restoration limits.

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.

Object identity matters

A name is an address, not the full identity of an object. Dropping and recreating a table can produce multiple historical objects with the same name. UNDROP TABLE by name targets the most recent eligible dropped version; inspect history before restoring.

Current Snowflake also documents selecting specific dropped objects using system-generated IDs with IDENTIFIER. This is useful for multiple historical versions, but requires identifying the right object in catalog history. The main exercise uses the simpler one-drop case.

Preserve a conflicting replacement

If a live object already occupies the original name, UNDROP fails. Rename the replacement to a new unused name instead of dropping it. After restoration, compare records, grants, downstream references and business ownership before deciding how to reconcile them.

Restoration is not a blanket approval to resume every consumer. A restored table may expose data to roles based on its restored grants; review access. A new replacement may have received valid writes that must be merged separately.

Restore database and schema containers

Restore a database before trying to resolve a table inside that missing database. Similarly restore a dropped schema before operating on its children. Use fully qualified names so the current worksheet schema does not hide the intended namespace.

A child dropped independently before its parent was dropped is not simply made active by restoring the parent. It may need separate UNDROP if still eligible. Short child retention can also prevent recovery of the desired state. Check the restored inventory, not just the success message.

Privileges and limitations

The current UNDROP TABLE reference lists CREATE TABLE on the containing schema, with parent access requirements. UNDROP SCHEMA requires CREATE SCHEMA on its database; database recovery requires CREATE DATABASE on the account. Use the owner of the disposable setup or ask your administrator to perform the exercise.

If history is gone or the object has entered Fail-safe, UNDROP cannot retrieve it. Verify retention before intentionally dropping anything. Temporary objects are not a durable cross-session recovery strategy. The optional database exercise must use the exact disposable database name and requires permission to create it.

Production decisions and common mistakes

Inspect history and preserve same-name replacements. Verify data, privileges and dependencies after restoration.

Do not run CREATE OR REPLACE repeatedly while investigating a drop: each replacement complicates object identity and recovery.

Key takeaways

Check the table’s independent drop, retention and original namespace. Restore it separately only if eligible; do not infer that a restored database guarantees every older dropped child returns.

Words used in this lesson
Namespace
The database/schema location and object name.
Object identity
The underlying object, distinct from a reusable name.
UNDROP
Restore an eligible dropped object.
Container
A database or schema holding child objects.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 4

UNDROP tables, schemas and databases safely

Active name
  • DROP_DEMO no longer present
Changed / needs review
Retained object
  • Original 4 orders
Historical / retained

Drop a disposable object

DROP removes the object from the active namespace. UNDROP addresses the object, unlike INSERT or UPDATE repairs of rows in an existing table.

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
  1. Drop a disposable object

    DROP removes the object from the active namespace. UNDROP addresses the object, unlike INSERT or UPDATE repairs of rows in an existing table.

    • Active name: DROP_DEMO no longer present
    • Retained object: Original 4 orders
  2. Inspect a naming conflict

    A replacement table now occupies DROP_DEMO. Do not drop it reflexively: it may contain valid work. Rename it to preserve both versions.

    • Current name: DROP_DEMO · new row
    • Preserve replacement: DROP_DEMO_NEW
  3. Restore the original

    UNDROP restores the eligible dropped object under its original name. Review restored grants and dependencies before letting consumers use it.

    • DROP_DEMO: Recovered original four
    • DROP_DEMO_NEW: Preserved replacement
  4. Restore containers deliberately

    For a dropped database or schema, restore the container first. Objects dropped independently before the container drop need their own investigation; container restoration is not unlimited history.

    • Database: Restore if eligible
    • Schema: Inspect children
    • Tables: Validate keys and access

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.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. 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.
  3. 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.
  4. 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.

Preserve the replacement and restore the table

Definition: Rename removes the namespace conflict without destroying either version.

When to use: Only the new DROP_DEMO object is intentionally dropped.

SQL · example
USE SCHEMA L2_OBJECTS_LAB.M14_LAB;
CREATE TABLE DROP_DEMO CLONE ORDERS;
DROP TABLE DROP_DEMO;
CREATE TABLE DROP_DEMO (NOTE VARCHAR);
INSERT INTO DROP_DEMO VALUES('new work - preserve me');
SHOW TABLES HISTORY LIKE 'DROP_DEMO' IN SCHEMA L2_OBJECTS_LAB.M14_LAB;
-- UNDROP TABLE DROP_DEMO would fail while this name is occupied.
ALTER TABLE DROP_DEMO RENAME TO DROP_DEMO_NEW;
UNDROP TABLE DROP_DEMO;
SELECT COUNT(*) AS N,SUM(AMOUNT) AS TOTAL FROM DROP_DEMO;
SELECT * FROM DROP_DEMO_NEW;
SHOW GRANTS ON TABLE DROP_DEMO;

What to expect and why

The restored original has four orders totaling 500. DROP_DEMO_NEW retains the replacement note. Neither object is discarded to resolve the conflict.

Expected result for the supplied input (not live output)
NTOTAL
4500.00

Optional schema and database restoration

Definition: Container restoration should be checked through child data.

When to use: Only if authorized to create these fresh disposable names; never substitute a production name.

SQL · example
CREATE SCHEMA L2_OBJECTS_LAB.M14_DROP_SCHEMA DATA_RETENTION_TIME_IN_DAYS=1;
CREATE TABLE L2_OBJECTS_LAB.M14_DROP_SCHEMA.ORDERS CLONE L2_OBJECTS_LAB.M14_LAB.ORDERS;
DROP SCHEMA L2_OBJECTS_LAB.M14_DROP_SCHEMA;
UNDROP SCHEMA L2_OBJECTS_LAB.M14_DROP_SCHEMA;
SELECT COUNT(*) FROM L2_OBJECTS_LAB.M14_DROP_SCHEMA.ORDERS;

-- Optional, separate database-creation permission required:
CREATE DATABASE M14_DROP_DATABASE DATA_RETENTION_TIME_IN_DAYS=1;
CREATE TABLE M14_DROP_DATABASE.PUBLIC.ORDERS CLONE L2_OBJECTS_LAB.M14_LAB.ORDERS;
USE DATABASE L2_OBJECTS_LAB;
DROP DATABASE M14_DROP_DATABASE;
UNDROP DATABASE M14_DROP_DATABASE;
SELECT COUNT(*) FROM M14_DROP_DATABASE.PUBLIC.ORDERS;
USE SCHEMA L2_OBJECTS_LAB.M14_LAB;

What to expect and why

Both restored child tables should contain four rows. Stop before the database block if you lack CREATE DATABASE; the table exercise still teaches the naming and recovery principles.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

A new live table has the dropped table’s name. What is the safe first step?

Try it yourself

You restored a database, but a table dropped a day before the database is absent. What should you investigate?

Compare your reasoning

Check the table’s independent drop, retention and original namespace. Restore it separately only if eligible; do not infer that a restored database guarantees every older dropped child returns.

Key takeaway

Inspect history and preserve same-name replacements. Verify data, privileges and dependencies after restoration.

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