Hive学习之更改表的属性

1、修改表名
    alter table table_name rename to new_table_name;
    例1:alter table ruoze_emp rename to emp;
2、修改列名
    alter table tablename change column column_orign column_new int(修改后列的属性) comment 'column_name'
    after severity;//可以把该列放到指定列的后面,或者使用‘first’放到第一位
    将表tablename中的列column_orign修改成column_new,同时指定修改后的列名称的属性,comment是这个列的注释
    例1:alter table emp change column age uage double comment 'column age' after id;
3、增加列
    alter table tablename add columns(column1 string comment 'xxxx',column2 long comment 'yyyy')
    例1:alter table emp add columns(age int);
4、替换表
    ALTER TABLE table_name [PARTITION partition_spec] ADD|REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...) [CASCADE|RESTRICT]                         -- (Note: Hive 1.1.0 and later)
    例1:ALTER TABLE emp REPLACE COLUMNS (age int, uage int);
5、查看表的属性
    desc formatted tablename;
6、修改表的属性
    (1)alter table table_name set tblproperties('property_name'='new_value');
       将table_name表中的comment属性值修改成'new_value';
    (2)alter table emp set serdeproperties ("field.delim"="\t");
       将表table_name中的字段分割符修改成'\t',注意,这是在表没有分区的情况下
    例1:create table emp(id int,uname string)row format delimited fields terminated by '#' lines terminated by '\n' stored as textfile;
       alter table emp set serdeproperties('field.delim'='\t');这条语句将t8表中的字段分隔符'#'修改成'\t';
    例2:create table emp(id int,uname string) partitioned by(dt=string) row foramt delimited fields terminated by '\n' stored as textfile;
       alter table emp partition(dt='20180108') set serdeproperties('field.delim=\t');
    (3)alter table table_name[partition] set location 'path'
       alter table emp set TBLPROPERTIES('EXTERNAL'='TRUE');//内部表转化成外部表
       alter table emp set TBLPROPERTIES('EXTERNAL'='FALSE');//外部表转成内部表

    注意:由于emp默认是内表,所以在删除表emp时,它的数据包括文件目录全部被删除,为了防止这种情况发生,可以将表emp修改成外表,
    通过语句:alter table emp set tblproperties('EXTERNAL'='TRUE');同样也可以将外部表修改为内部表,
    可以通过语句:alter table city set tblproperties('EXTERNAL'='FALSE');
    (4)其他修改表属性的命令:
       alter table properties; alter serde properties;
       alter table/partition file format;
       alter table storage properties;
       alter table rename partition;
       alter table set location;
    详细说明可以参考:Hive官网,在官网中找:wiki LanguageManual DDL(https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterTable)来查询详细介绍

若泽大数据交流群:671914634

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31511218/viewspace-2149885/,如需转载,请注明出处,否则将追究法律责任。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值