DROP TABLE removes one or more tables from a BigQuery dataset, freeing storage and metadata.
Loop through INFORMATION_SCHEMA.TABLES (or __TABLES_SUMMARY__) to build a comma-separated DROP TABLE list, then execute it with EXECUTE IMMEDIATE. BigQuery doesn’t support wildcards like DROP TABLE dataset.*
.
Create a BigQuery script that (1) assembles the DDL string, (2) optionally verifies the list, and (3) runs the statement in a single transaction. Add IF EXISTS to avoid errors.
Yes. Filter out rows in INFORMATION_SCHEMA.TABLES by table_name NOT IN ('Customers')
or by older than a given creation time.
1. DECLARE a string variable.
2. SELECT STRING_AGG('DROP TABLE IF EXISTS `' || table_schema || '.' || table_name || '`;') AS ddl FROM INFORMATION_SCHEMA.TABLES.
3. EXECUTE IMMEDIATE ddl.
IF EXISTS prevents your script from failing if another process already removed a table between DDL generation and execution.
PRINT the generated DDL or insert it into an audit table before execution. BigQuery Job History also records all DDL jobs.
BigQuery DDL jobs follow standard limits (6 hours). Dropping thousands of tables typically completes in seconds.
Yes. Space is reclaimed right after the job finishes, lowering your storage costs.
Only if you enabled table snapshots or backups. Otherwise, the data is permanently deleted.