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'
);
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;
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重新将表的列给更新替换了
4.重命名表名
# 修改表名
alter table table_name rename to table_name2;
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;
还没有评论,来说两句吧...