hive的DDL

一、增删改查数据库
1)增

 create database[if not exists] database_name
 [comment 'beizhu']
 [location 'hdfs_path'] //指定存储路径,默认为/user/hive/warehouse/database_name.db
 [with dbproperties(property_name=property_value)]//一般都是创建时间

2)删

drop database databases_name [cascade]//加上cascade可以清空全部数据,而不加的话,只能删除空的数据库(即数据库中没有数据表)

二、增删改查数据表
1)增

create [external] table table_name
([columns id idtype])
[partitioned by(columns id idtype)]
[clustered by (columns id )] 
[stored by (id(desc|asc)) into num_buckets buckets]
[row format delimited]
[stored as text_format]
[location 'hdfs_inpath']
[tblproperties property_name=proper_value ...];
[as sql]

hive中表分为两类,一类为外部表,一类为内部表(管理表)
一、内部表
内部表:在创建 表的语句中 不加 external ,创建的就是内部表
内部表一般都是作为案例来使用,或者说存储一些临时数据,内部表的数据不能被多个表共享(含义是:表中数据会随着表的删除而被删除)
二、外部表
外部表:外部表数据一般都是会被共享,或在多个阶段进行使用,当表被删除时,表中数据并不会被删除,
内部表和外部表的相互转换
在meatstore里面存有每个表的相关信息,当内部表想要转换为外部表时
通过

alter tabl table_name set tblproperties('EXTERNAL'='TRUE');
alter tabl table_name set tblproperties('EXTERNAL'='FALSE');

2)修改表

alter table table_name replace old_name new_name new_type
// alter table test id stu_id int; 替换列,可以多对一
alter table table_name add new_name new_type
//alter table test stu_id int; 可以同时增加多列
alter table table_name change old_name new_name new_type
//alter table test change  id stu_id string
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值