Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to Drop Hive Database with Tables in it ?

avatar
Contributor

DROP DATABASE IF EXISTS userdb CASCADE;

By using CASCADE, tables in userdb will be deleted first and then the database will be dropped.

Is it safe to use cascade for Dropping the Hive database?

Is there any best practice?

9 REPLIES 9

avatar
Contributor

avatar
@Dhiraj

DROP DATABASE will fail if the database is not empty. To drop the tables in the database as well, use DROP DATABASE ... CASCADE

avatar
Contributor

@Sridhar Reddy I know, CASCADE will help in dropping the database with tables in it. Is this an only way or are there any best practices?

avatar
@Dhiraj

Yes, this is the only way to drop the database along with tables inside it. I haven't faced any issues till now but I;m not sure of best practices

avatar
@Dhiraj

Yes, this is the only way to drop the database along with tables inside it. I haven't faced any issues till now but I;m not sure of best practices

avatar
Contributor

@Sridhar Reddy Using cascade for dropping DB will delete the entire directory of DB in given HDFS location and also data of other DB which are in/under that location of dropped DB. So it is not recommended to use CASCADE for dropping DB.

avatar

@Dhiraj

If the idea is to drop the database and all tables within, then the db directory from HDFS is sure to be removed. Is the use case to remove the tables within than to remove the database and it's directory structure?

avatar
Contributor

@Sindhu Yes, idea is to drop the database and all tables within and to remove the db directory from HDFS too.

avatar
@Dhiraj

Then, you need to run 'Drop database cascade'.