Hive - Create Database
In Hive, the database is considered as a catalog or namespace of tables. So, we can maintain multiple tables within a database where a unique name is assigned to each table. Hive also provides a default database with a name default .
- Initially, we check the default database provided by Hive. So, to check the list of existing databases, follow the below command: -
hive> show databases;
Here, we can see the existence of a default database provided by Hive.
- Let’s create a new database by using the following command: -
hive> create database demo;
So, a new database is created.
- Let’s check the existence of a newly created database.
hive> show databases;
- Each database must contain a unique name. If we create two databases with the same name, the following error generates: -
- If we want to suppress the warning generated by Hive on creating the database with the same name, follow the below command: -
hive> create a database if not exists demo;
- Hive also allows assigning properties with the database in the form of key-value pair.
hive>create the database demo
>WITH DBPROPERTIES ('creator' = 'Gaurav Chawla', 'date' = '2019-06-03');
- Let’s retrieve the information associated with the database.
hive> describe database extended demo;