Hive - Database

About

All table in hive are in a database.

The database:

  • has a namespaces function
  • are used to enforce security for a user or group of users.

Management

Set

  • Qualify the table names db_name.table_name
  • or issue the USE statement before the query statement (since Hive 0.6).
USE database_name;
SELECT query_specifications;
USE default;

Current

SELECT current_database();
default/

Describe

DescribeDatabase

DESCRIBE DATABASE [EXTENDED] db_name;
DESCRIBE SCHEMA [EXTENDED] db_name;     -- (Note: Hive 1.1.0 and later)

Example

DESCRIBE DATABASE default;
+----------+------------------------+----------------------------+-------------+-------------+-------------+--+
| db_name  |        comment         |          location          | owner_name  | owner_type  | parameters  |
+----------+------------------------+----------------------------+-------------+-------------+-------------+--+
| default  | Default Hive database  | adl://home/hive/warehouse  | public      | ROLE        |             |
+----------+------------------------+----------------------------+-------------+-------------+-------------+--+

Create

CreateDatabase

CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name
  [COMMENT database_comment]
  [LOCATION hdfs_path]
  [WITH DBPROPERTIES (property_name=property_value, ...)];

List / Show

show databases;

Powered by ComboStrap