Create, Use and Drop a Database in Hive

We will see how to Create, Use and Drop a database in Hive.

Create a Database

#List all the databases
0: jdbc:hive2://localhost:10000> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
+----------------+--+

#Create a new Database
0: jdbc:hive2://localhost:10000> create database mydb;

#List all the databases
0: jdbc:hive2://localhost:10000> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
| mydb           |
+----------------+--+

Use a Database

Once we use a specific database, then all the queries can use the tables directly from that database. We need not qualify the table names with their database name in our queries.

#Use a database
0: jdbc:hive2://localhost:10000> use mydb;

Drop a Database

#Drop a database, if there are no tables in the database
0: jdbc:hive2://localhost:10000> drop database mydb;

#Drop a database by deleting all the tables in it
0: jdbc:hive2://localhost:10000> drop database mydb cascade;

 

Leave a Reply

Your email address will not be published. Required fields are marked *