How to manipulate Database in Hive

Tram Ho

This is the fourth post in the series about Hive, this article let’s use learn about how to manipulate the database in Hive ^^

1. Create database

Hive is a database technology that can identify databases and tables for structured data analysis. The topic for structured data analysis is to store data in a tabular manner and to transfer queries to analyze data. Hive contains a default database called default.

A database in Hive is a namespace or a collection of tables. The syntax is as follows:

Here, IF NOT EXISTS is an optional clause, informing the user that a database with the same name already exists. We can use SCHEMA instead of DATABASE in this command. The following query is executed to create a database named userdb:

or

The following query is used to verify the database listing:

JDBC Program

JDBC to create the database is given below.

Save the program in a file named HiveCreateDb.java. The following commands are used to compile and execute this program.

Output:

2. Delete the database

Drop Database is a command that removes all tables and deletes the database. Its syntax is as follows:

The following queries are used to delete the database. Let’s assume that the database name is userdb.

The following query removes the database using CASCADE. It means dropping the corresponding tables before dropping the database.

The following queries remove the database using SCHEMA.

This statement has been added in Hive 0.6.

JDBC Program

JDBC program to remove the database is given below.

Save the program in a file named HiveDropDb.java. Given below are the commands to compile and execute this program.

Output:

Conclude

How to manipulate Database in Hive is also simple, isn’t it, in the next article, I will present the next article on how to manipulate tables in Hive’s database, see ya !!

Share the news now

Source : Viblo