UmaMahesh1
Honored Contributor III

Hi @Mahesh Babu Uppala​ 

You can use the following method to delete only the duplicate tables

%scala
val tables = spark.sql("""SHOW TABLES""").createOrReplaceTempView("tables")
val temp_tables = spark.sql("""select tableName from tables where tableName like '%-1%' """)
temp_tables.collect().foreach(row => println("DROP TABLE IF EXISTS " + row.toString().replace("[", "").replace("]", "") + ";"))

You will get the sql command in a string...you can either copy this cell output to another cell directly and run it or you can automate the process by storing this output into a variable and then calling it through a loop...Better way would be to simply copy the output and execute it.

Hope this helps..Cheers...

Uma Mahesh D