How to Drop All Tables from Lakehouse in Microsoft Fabric | Microsoft Fabric Tutorial for Beginners

How to Drop All Tables from Lakehouse in Microsoft Fabric

How to Drop All Tables from Lakehouse in Microsoft Fabric

Microsoft Fabric Tutorial for Beginners

📘 Overview

If you're working with a Microsoft Fabric Lakehouse and want to clean up your environment, dropping all existing tables can help you reset your workspace. This tutorial shows how to do that programmatically using PySpark and the spark.catalog.

🔍 Step 1: List All Tables in the Lakehouse

Use the Spark catalog API to fetch all tables in the current Lakehouse:

# List all tables
tables = spark.catalog.listTables()

This returns metadata such as table name, database, and type (managed or external).

🔁 Step 2: Loop Through and Drop Each Table

Loop through each entry and run a DROP TABLE command:

for table in tables:
    table_name = table.name
    spark.sql(f"DROP TABLE IF EXISTS {table_name}")

This ensures that each table is removed cleanly from the catalog.

💡 Notes

  • This approach works only on tables in the current Lakehouse context.
  • Always double-check before running this in production — this operation is irreversible!
  • Works well during automated clean-up workflows or notebook resets.

🎬 Watch the Demo Video

Blog created with help from ChatGPT and Gemini.