hive 增加字段 修改注释

一、普通建表添加注释
在Hive中创建表可使用以下语句,添加中文注释方便识别。

– 创建临时表
create table tb_test
(
id varchar(100), – 用户id
age varchar(100) – 年龄
) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'STORED AS TEXTFILE;

– 添加注释
create table tb_test
(
id varchar(100) comment ‘用户id’, – 用户id
age varchar(100) comment ‘年龄’ – 年龄
) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'STORED AS TEXTFILE;

– 查询
select * from tb_test;
– 查看描述
desc tb_test;
– 结果
col_name data_type comment
id varchar(100) 用户id
age varchar(100) 年龄
二、修改表注释
修改表注释可使用以下语句:

– 修改表注释
alter table tb_test set tblproperties(‘comment’ = ‘测试表’);

– 查看
desc formatted tb_test;
三、修改字段注释
修改字段注释可使用以下语句:

– 修改字段注释
alter table tb_test change column id id string comment ‘用户号码’;

– 查看
desc formatted tb_test;
四、添加字段
可通过以下语句进行添加字段:

– 添加字段
alter table tb_test add columns (gender string comment ‘性别’);

– 添加多个字段
alter table tb_test add columns
(
aa string comment ‘aa’,
bb string comment ‘bb’,
cc string comment ‘cc’
);

– 查看
desc formatted tb_test

猜你喜欢

转载自blog.csdn.net/ZK_0705/article/details/126838525
今日推荐