Hive添加列、修改列(调整位置)、删除列操作等
张行之 2020-09-11 18:35:51 5433 收藏 18
分类专栏: 大数据 文章标签: 数据库 hive alter
版权
大数据
专栏收录该内容
84 篇文章4 订阅
订阅专栏
1.添加1列或多列
添加1列
alter table table_name add columns(
user_id bigint comment ‘用户ID’
);
添加多列
alter table table_name add columns(
name string comment ‘用户名称’,
city string comment ‘城市’,
sex string comment ‘用户性别’,
age string comment ‘用户年龄’,
phone string comment ‘用户手机’,
email string comment ‘用户邮箱’,
unqiue_id string comment ‘身份证ID’
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2.修改列名/类型/位置/注释
将性别(sex)名称改成gender,类型改成int,注释改成“性别”
alter table table_name change sex gender int comment ‘性别’;
将age字段类型改为int,并将位置移动到name字段后面
alter table table_name change age age int comment ‘用户年龄’ after name;
1
2
3
4
5
3.删除列/更新列
由于数据脱敏,我们需要删除unqiue_id列
alter table table_name replace (
user_id bigint comment ‘用户ID’,
name string comment ‘用户名称’,
city string comment ‘城市’,
sex string comment ‘用户性别’,
age string comment ‘用户年龄’,
phone string comment ‘用户手机’,
email string comment ‘用户邮箱’
);
相当于使用replace重新将表的列给更新替换了
1
2
3
4
5
6
7
8
9
10
11
4.重命名表名
修改表名
alter table table_name rename to table_name2;
1
2
5.限制表的查询和删除操作
限制表的dt='2020-01-01’分区不能被drop掉
ALTER TABLE table_name PARTITION(dt=‘2020-01-01’) ENABLE NO_DROP;
限制表的dt='2020-01-01’分区不能被查询
ALTER TABLE table_name PARTITION(dt=‘2020-01-01’) ENABLE OFFLINE;
————————————————
版权声明:本文为优快云博主「张行之」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/qq_33689414/article/details/108539578