Hive Commands

Hive commands supports Data definition Language (DDL), Data Manipulation Language (DML) and User defined functions is shown in the below diagram.

1. Create database

A database in Hive is a collection of tables.

Syntax

hive> create database <database name>;

Example

hive> create database beyond corner;

2. Show database

This command used to verify a database list.

hive> show databases;

3. Use database

     This command is used to select database from the list.

hive>use database name;

4. Drop database

This command is used to delete database.

 Syntax

hive> drop database <database name>;

Example

hive>drop database beyond corner;

5. Create internal table

Below command is used to create Internal table, when its created by default data stored in warehouse directory.

Example

hive>create database beyond corner;

hive>Use beyond corner;

hive>create table emp (id int,name string,salary string)

>row format delimited

>fields terminated by ‘,’;

Loading data into the internal table

Consider emp.csv

id,name,salary

1,ram,24000

2,sita,30000

3,raju,10000

4,roy,15000

hive>load data local inpath ‘emp.csv’ overwrite into table emp;
Display the content of an internal table
hive>select * from emp;
Describe the structure of an internal table
hive>desc emp;

6. Create external table

Below command is used to create external table, when its created data stored outside the warehouse directory(we need to specify the path).

Example

hive>use beyond corner;

hive>create external table emp(id int,name string,salary int)

>row format delimited

>fields terminated by ‘,’

>location ‘path’;

Loading data to the external table
hive>load data local inpath ‘emp.csv’ overwrite into table emp;
Display the content of an external table.
hive>select * from emp;
Describe the structure of an internal table.
hive>desc emp;

7. Alter table

It is used to alter a table in Hive.

Example

hive> alter table emp rename to employee;

hive> alter table employee add columns (age int,city string);

Conclusion

From the Above topic we can conclude that hive commands supports DDL and DML commands, remaining commands are coverd in the next topics.

Reference

https://en.wikipedia.org/wiki/Apache_Hive