HIVE的ddl操作

hive的ddl操作
库:

修改数据库不支持
创建数据库:create database	mading;
切换数据库:use mading;
查看数据库列表:show databases;
	//模糊查询:show databases like 'test*';
查看正在使用的数据库:show current_database();
查看数据库的详细信息:desc database mading;
删除数据库:drop database mading;//只能删除空数据库
		drop database cascade mading;//	可以删除非空数据库

表:

1.
external 外部表 ,删除时只删除元数据,保留原始数据,建表指定表的存储目录
managed 内部表 ,默认,删除时和元数据一起,建表用默认路径可以
2.
分区:为了提高查询性能,对庞大的表进行切分,把经常查询的字段作为分区字段,把数据划分成不同的数据目录,这样就避免的全表扫描,
分桶:1可以提升抽样效率,2可以提升join性能。相对于分区表颗粒度更细,按照分桶字段划分为不同的文件,指定分桶字段和分桶个数,分桶字段.hashCode&分桶个数
3.
fields terminated by 指定列分隔符
lines terminated by 指定行分隔符
items terminated by 指定集合中元素的分隔符

查看表的描述信息

desc 表名
desc extended 表名
desc formatted 表名

查看表的列表信息

show tables;
show tables in database_1;//查看数据库中的表
show tables like '';//模糊查询

修改表

1.修改表名:
alter table 表名 rename to 新表名
2.修改表字段
alter table 表名 change 字段 新字段 类型;
3.增加表字段
alter table 表名 add columns (score int);
4.删除表字段
alter table 表名 delete score;
5.替换全表的所有字段
alter table 表名 replace columns(xxx string);
6.	清空表数据,但是会保留表结构
truncate table stu;
7.

加载数据到表

load data inpath '/stuin' into table stu;

建表案例
950003,刘梓晨,女,17,IS

1.建内部表

create table if not exsits stu(id int,name string,sex string,age int comment '16-24',department string) comment 'mystudent' row format delimited fields terminated by ',' stored as textfile location '/user/stu';

2.建外部表

create external table if not exsits stu(id int,name string,sex string,age int comment '16-24',department string) comment 'mystudent' row format delimited fields terminated by ',' stored as textfile location '/user/stu';

3.建一个分区表

分区字段一定不能是建表语句中的字段
create table stu(id int,name string,sex string,department string) partitioned by(age int) row format delimited fields terminated by ',';
添加分区的语法:
alter table stu add if not exsits partition(age=18);
修改分区的存储路径
alter table stu partition (age =17) set location '';
删除分区
alter table stu drop if exsits partition (age =17);

4.建一个分桶表

create table stu(id int,name string,sex string,department string) partitioned by(age int) clustered by (name) sorted by (age desc) into 8 buckets row format delimited fields terminated by ',';

5.ctas 建表语句

create table as select ... from ... 

6.表复制

like关键字
只会复制表结构,不会复制表数据
create table stu1 like stu;

其他辅助命令

show functions;//查看hive函数列表
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值