0% found this document useful (0 votes)
96 views

Creating and Managing Database

This document outlines the steps to create various tables and databases in Hive: 1) It creates an EMPLOYEE_DATA table to store employee data and loads sample employee data from a file into it. 2) It similarly creates tables for departments, orders, and order details to store relevant data and loads sample data into them from files. 3) It creates additional databases like empdata1 and HDP1.

Uploaded by

PEPETI RAVI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Creating and Managing Database

This document outlines the steps to create various tables and databases in Hive: 1) It creates an EMPLOYEE_DATA table to store employee data and loads sample employee data from a file into it. 2) It similarly creates tables for departments, orders, and order details to store relevant data and loads sample data into them from files. 3) It creates additional databases like empdata1 and HDP1.

Uploaded by

PEPETI RAVI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1) Create the EMP-data:

CREATE TABLE IF NOT EXISTS EMPLOYEE_DATA


EMP_NAME SRING COMMENT ‘THIS COL. STORE THE NAME OF EMPLOYEE’
EMP_ID INT COMMENT’THIS COL.STORES THE ID OF EMPLOYEE’
EMP_DEPARTMENT INT
ROW FORMAT DELIMITED
FIELDS TERMINATED BY’,’;
OK
2) Create an employee table in the above created database 'empdata' with the below
set of data
empid, age, salary, department
1001,25,23000,D1
1004,27,27000,D3
1002,23,21000,D2
1003,28,33000,D2
1006,31,29000,D3
1007,41,38000,D4
1009,27,21000,D3

Creating the sample txt to insert the data in to the hive


hive> LOAD DATA LOCAL INPATH '/home/user/sample.txt'
OVERWRITE INTO TABLE employee;

Create a departments table in the above database 'empdata' with the below set of
data
deptid,deptname,deptloc
D1,IT,BDC
D2,HR,CDC
D3,Finance,HDC
D4,Sales,KDC
Create the EMP-data:
CREATE TABLE IF NOT EXISTS EMPLOYEE_DATA
EMP_NAME SRING COMMENT ‘THIS COL. STORE THE NAME OF EMPLOYEE’
EMP_ID INT COMMENT’THIS COL.STORES THE ID OF EMPLOYEE’
EMP_DEPARTMENT INT
ROW FORMAT DELIMITED
FIELDS TERMINATED BY’,’;
OK

hive> LOAD DATA LOCAL INPATH '/home/user/empdata.txt'


OVERWRITE INTO TABLE empdata;

Create another database named empdata 1


Create the EMP-data1:
CREATE TABLE IF NOT EXISTS EMPLOYEE_DATA
EMP_NAME SRING COMMENT ‘THIS COL. STORE THE NAME OF EMPLOYEE’
EMP_ID INT COMMENT’THIS COL.STORES THE ID OF EMPLOYEE’
EMP_DEPARTMENT INT
ROW FORMAT DELIMITED
FIELDS TERMINATED BY’,’;
OK

Create a table named order to store the below data. Save the data into a file named
orders.txt

Order.txt
OrderID, CustID, OrderDate
101,C001,10/12/2015
102,C002,11/10/2015
103,C003,15/12/2015
Create the order
CREATE TABLE IF NOT EXISTS order
Order _ID INT COMMENT ‘THIS COL. STOREa ORDERID’
CUST_ID INT COMMENT’THIS COL.STORES THE ID OF CUSTOMER’
ORDER_DATE INT
ROW FORMAT DELIMITED
FIELDS TERMINATED BY’,’;
OK

hive> LOAD DATA LOCAL INPATH '/home/user/ORDER.txt'


OVERWRITE INTO TABLE empdata;
Create a table named order_detail to store the below data. Save the data into a
file named Order_details.txt
Order_details.txt
OrderID,ItemID,Qty,Rate
101,Item1,10,2500
101,Item2,2,500
102,Item3,5,400
102,Item1,5,500
103,Item1,10,500

Create the order_detail


CREATE TABLE IF NOT EXISTS order_detail
Item _ID INT COMMENT ‘THIS COL. STOREa item_ID’
CUST_ID INT COMMENT’THIS COL.STORES THE ID OF CUSTOMER’
Qyt INT
Rate INT
ROW FORMAT DELIMITED
FIELDS TERMINATED BY’,’;
OK
Create a Database named hdp1
Create a database HDP1
List out all the existing databases in Hive
Show databases

You might also like