Removes every table from a chosen Snowflake database-schema in a single operation.
Dropping all tables deletes every table object in a target database-schema, freeing storage and releasing names. The action is irreversible; back up critical data first.
Generate DROP TABLE statements with INFORMATION_SCHEMA, aggregate them with LISTAGG, and run the resulting script with EXECUTE IMMEDIATE. This avoids manual deletion and respects transactional order.
EXECUTE IMMEDIATE ( SELECT LISTAGG('DROP TABLE "' || table_schema || '"."' || table_name || '";', ' ') FROM MYDB.INFORMATION_SCHEMA.TABLES WHERE table_schema = 'PUBLIC');
The executing role needs OWNERSHIP or DROP privilege on each table plus USAGE on the database and schema. SYSADMIN usually suffices.
Yes. Add AND table_name ILIKE '%TEST%'
in the WHERE clause to target only matching tables, keeping production tables safe.
Run the SELECT portion alone to list candidate tables. Verify the list, then run EXECUTE IMMEDIATE when satisfied.
• Always run in a sandbox or off-hours.
• Take a clone of the schema for rollback.
• Use separate dev and prod warehouses to avoid accidental data loss.
Missing schema filter: Omitting WHERE table_schema='PUBLIC'
deletes tables in every schema. Always filter.
Insufficient privileges: Running as a role without OWNERSHIP causes partial drops. Switch to SYSADMIN or GRANT needed rights.
Dynamic SQL scales to hundreds of tables, guarantees consistent syntax, and reduces human error compared with copy-pasting individual DROP statements.
Snowflake lacks a native DROP SCHEMA CASCADE equivalent, so dynamic SQL is currently the recommended pattern.
If Time Travel is enabled, use CREATE TABLE ... AT
or a clone to restore dropped tables within the retention period.
No. Each DROP TABLE executes individually; failures stop subsequent drops unless you wrap calls in TRY/CATCH JavaScript or handle errors manually.