Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
italogomes
New Member

Truncar tabela

Queria saber se existe alguma forma de truncar uma tabela delta do meu lakehouse?

1 ACCEPTED SOLUTION
2 REPLIES 2
v-jingzhan-msft
Community Support
Community Support

Hi @italogomes 

 

Here is one method with notebook.

# Step 1: Read the existing Delta table and get its schema
tablePath = "Tables/TableName"
read_df = spark.read.format("delta").load(tablePath)
schema = read_df.schema

# Step 2: Create an empty dataframe with the same structure
empty_df = spark.createDataFrame([], schema)

# Step 3: Save the empty dataframe to overwrite the existing Delta table
empty_df.write.format("delta").mode("overwrite").save(tablePath)

 

Result:

vjingzhanmsft_0-1724395238441.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

JanFabricDE_carousel

Fabric Monthly Update - January 2025

Explore the power of Python Notebooks in Fabric!

JanFabricDW_carousel

Fabric Monthly Update - January 2025

Unlock the latest Fabric Data Warehouse upgrades!

JanFabricDF_carousel

Fabric Monthly Update - January 2025

Take your data replication to the next level with Fabric's latest updates!