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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.