cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Programatically remove external table completely (Azure)

johnb1
Contributor

Hi!

I have created external tables with data stored in an Azure storage account.

Is there a way to not only drop the tables but also remove the underlying folder in the storage account which contains the table's data? I want to do this from Databricks in either SQL or Python.

1 REPLY 1

Panda
Valued Contributor

@johnb1 

You can achieve this with the code below. Please review.

table_name = "table_name"
location = "abfss://container@storage-account.dfs.core.windows.net/path/to/table/data/" 

spark.sql(f"DROP TABLE IF EXISTS {table_name}")
dbutils.fs.rm(location, recurse=True)

########################################
#Note even you can extract location by doing below
df = spark.sql(f"DESCRIBE DETAIL {table_name}")
location = df.select("location").collect()[0]["location"]

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group