Categories

1 Answer

Sep 8, 2019
Hive - Drop Database

In this section, we will see various ways to drop the existing database.

Let's check the list of existing databases by using the following command: -

hive> show databases;  

Hive Drop Database

Now, drop the database by using the following command.

hive> drop database demo;  

Hive Drop Database

Let's check whether the database is dropped or not.

hive> show databases;  

Hive Drop Database

As we can see, the database demo is not present in the list. Hence, the database is dropped successfully.

If we try to drop the database that doesn't exist, the following error generates:

Hive Drop Database

However, if we want to suppress the warning generated by Hive on creating the database with the same name, follow the below command:-

hive> drop database if exists demo;  

Hive Drop Database

In Hive, it is not allowed to drop the database that contains the tables directly. In such a case, we can drop the database either by dropping tables first or use Cascade keyword with the command.

Let's see the cascade command used to drop the database:-

hive> drop database if exists demo cascade;  

This command automatically drops the tables present in the database first.
Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

Madanswer
Sep 7, 2019 in Big Data | Hadoop
Sep 7, 2019 in Big Data | Hadoop
Oct 12, 2019 in Big Data | Hadoop
...