【hive】--- hive数据库和表的操作

创建数据库:

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’);

 

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值