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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Dhanapal
Frequent Visitor

Drop and re-create table Using notebook, While loading objects doesn't exist while insert & fail

We have a notebook, which has script as below (refer the screen shot)

 

Drop table from Lakehouse and Create table same in takehouse. When we try to load data, its getting some weird error .. saying "Table is not found" or 

'Error name - AnalysisException, Error value - [TABLE_OR_VIEW_NOT_FOUND] The table or view `lh_sales`.`dim_cots` cannot be found.

Dhanapal_0-1723141576459.png

 

To Resolve notebook issue, We have added some pyspark script to refresh meta_data, but still failing.. If we re-run the failure step & its getting executed successfully. Some of my friends says, its intermittent failure.. Any alternative or perment fix to resolve this type of issues ?

Dhanapal_1-1723141701218.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Dhanapal ,

 

I understand your need now, here's my suggestion.

 

Like mentioned in the case below, you can explicitly refresh the table metadata using the spark.catalog.refreshTable("table_name") command.

apache spark - How to refresh a table and do it concurrently? - Stack Overflow

 

I ran some tests and deleted a table named salesorders.

vhuijieymsft_0-1723169418978.png

 

The error occurs when I create the form with the same name again.

vhuijieymsft_1-1723169418985.png

 

After using the following command, the table with the same name is created successfully.

# Define the table name
table_name = "salesorders"

# Drop and create table with actual schema
spark.sql(f"""
    DROP TABLE IF EXISTS {table_name}
""")

spark.sql(f"""
    CREATE TABLE {table_name} (
        SalesOrderID INT,
        OrderDate DATE,
        CustomerID INT,
        Item STRING,
        Quantity INT,
        UnitPrice DOUBLE,
        Tax DOUBLE,
        TotalAmount DOUBLE
    )
""")

vhuijieymsft_2-1723169475879.png

 

Please note that when you use it, change the table names, column names, and data types to your own.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Dhanapal ,

 

I understand your need now, here's my suggestion.

 

Like mentioned in the case below, you can explicitly refresh the table metadata using the spark.catalog.refreshTable("table_name") command.

apache spark - How to refresh a table and do it concurrently? - Stack Overflow

 

I ran some tests and deleted a table named salesorders.

vhuijieymsft_0-1723169418978.png

 

The error occurs when I create the form with the same name again.

vhuijieymsft_1-1723169418985.png

 

After using the following command, the table with the same name is created successfully.

# Define the table name
table_name = "salesorders"

# Drop and create table with actual schema
spark.sql(f"""
    DROP TABLE IF EXISTS {table_name}
""")

spark.sql(f"""
    CREATE TABLE {table_name} (
        SalesOrderID INT,
        OrderDate DATE,
        CustomerID INT,
        Item STRING,
        Quantity INT,
        UnitPrice DOUBLE,
        Tax DOUBLE,
        TotalAmount DOUBLE
    )
""")

vhuijieymsft_2-1723169475879.png

 

Please note that when you use it, change the table names, column names, and data types to your own.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.