Hive - Database

1 - 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.

3 - Management

3.1 - 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;

3.2 - Current


SELECT current_database();


default/

3.3 - 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        |             |
+----------+------------------------+----------------------------+-------------+-------------+-------------+--+

3.4 - Create

CreateDatabase


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

3.5 - List / Show


show databases;


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap