一.数据库操作
1.创建数据库
create database financials;
2.创建数据库,避免抛出错误信息
create database if not exists financials;
3.查看hive中包含的数据库
show databases;
4.显示当前所在数据库
use financials ;
5.删除空数据库
drop database if exists financials;
6.删除有表格的数据库
drop database if exists financials cascade;
7.修改数据库
alter database financials set dbproperties (`edited-by`=`job dba`);
二. 创建表
1.创建内部表
CREATE TABLE if not exists financials.employees1(
name STRING COMMENT 'Empolyee name',
salary FLOAT COMMENT 'Empolyee salary',
subordinates ARRAY<STRING> COMMENT 'Names of subordinates',
duduction MAP<STRING,FLOAT>
COMMENT 'Keys are deductions names,vlaues are percentages',
address STRUCT<street:STRING,city:STRING,state:STRING,zip:INT>
COMMENT 'Home address')
COMMENT 'Description ofthe table'
LOCATION '/user/hive/warehouse/financials.db/employees'
TBLPROPERTIES('creator'='li','created_at'='2014-1-23 10:00:00');
2.创建外部表
CREATE EXTERNAL TABLE financials.employees2(
ts String,
uid String,
keyword String,
rank int,
order int,
url String)
comment 'this
ts String,
uid String,
keyword String,
rank int,
order int,
url String)
comment 'this