创建数据库:
create database if not exists test;
切换数据库:
use test;
显示当前的数据库:
select current_database();
删除数据库:
drop database if exists test;
hive表分为普通表,外部表,分区表,外部分区表
创建表:
加tblproperties(‘creator’=’derry’);可以添加表的属性说明
指定表的存储位置
Location ‘’;
分区表:
分区表的创建需要在创建语句后面添加 partitioned by (country string,school string);
Set hive.mapred.mode=strict;
此时查询就需要带where分区条件
Select * from employees where country=’china’ and school=’jiaoda’;
Set hive.mapred.mode=nonstrict;此时可以不加
查看分区表的分区:show partitions employee;
外部表:
外部表的创建需要在创建表时加create external table if not exists stocks();
外部分区表:
在创建外部分区表时需要添加
create external table if not exists log_messages()partitioned by(year int,month int,day int) row farmat delimited fields terminated by ‘\t’;
增加分区:
Alter table log_messages add partition(year=2012,month=1;day=2)
查看表信息:
describe emloyees; 显示包含属性等的一些其他信息 describe extended employees;
表重命名:
ALTER table employees rename to employee;
修改列信息:
Alter table employees change column name changeName int;
增加列:
Alter table employees add columns (age int comment ‘ age of person’);
替换列:(即对该表的结构重新增加)
Alter table employees replace columns(name string,age int ,salary float,subordinates array<string>,deducation map<string,float>,address struct<street:string,city:string,state:string,zip:int>);
修改表属性:
Alter table student set tblproperties(‘creator’=’derryliu’);
1380

被折叠的 条评论
为什么被折叠?



