Quicktostudy
11/16/2018   
Hive Tutorial
Home »  Hive » Hive Create Database

Hive Create Database


The database in Hive describes a collection of tables that are used for a similar purpose or belong to the same groups. If the database is not specified, the default database is used. Whenever a new database is created, Hive creates a directory for each database at /user/hive/warehouse, defined in hive.metastore.warehouse.dir. For example, the mydatabase database is located at /user/hive/datawarehouse/mydatabase.db. However, the default database does not have its own directory. The following is the core DDL for Hive databases:

Create the database in hive without checking whether the database already exists in hive

hive> CREATE DATABASE mydatabase;

Create the database in hive and check whether the database already exists in hive

hive> CREATE DATABASE IF NOT EXISTS mydatabase;

Create the database in hive with location, comments, and metadata information

hive> CREATE DATABASE IF NOT EXISTS mydatabase
         > COMMENT 'hive database demo'
         > LOCATION '/hdfs/mydirectory'
         > WITH DBPROPERTIES ('creator'='myuser','date'='2016-01-01');

Show database in hive

The SHOW keywords in Hive are used to show the definition information for most of the Hive objects, such as tables, partitions, and so on. The SHOW statement supports a wide range of Hive objects, such as tables, tables' properties, table DDL, index, partitions, columns, functions, locks, roles, configurations,transactions, and compactions.

hive> SHOW DATABASES;
+----------------+
| database_name  |
+----------------+
| default        |
+----------------+

Describe the database in hive

The DESCRIBE statement supports a small range of Hive objects, such as databases, tables, views, columns, and partitions. However, the DESCRIBE statement is able to provide more detailed information combined with the EXTENDED or FORMATTED keywords.

hive> DESCRIBE DATABASE default;
+-------+----------------------+-----------------------------+
|db_name| comment              | location                    |
+-------+----------------------+-----------------------------+
|default|Default Hive database | /user/hive/warehouse        |
+-------+----------------------+-----------------------------+

Use the database in hive

hive> USE mydatabase;

Contact Us| About Us| Terms| Privacy Policies
Powered by Lorquins Technologies© 2017 QuickToStudy.com. All Rights Reserved