修改表
重命名表
语法
ALTER TABLE table_name RENAME TO new_table_name
实操案例
hive (default)> alter table dept_partition2 rename to dept_partition3;
增加/修改/替换列信息
语法
更新列
ALTER TABLE table_name CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENT col_comment] [FIRST|AFTER column_name]
增加和替换列
ALTER TABLE table_name ADD|REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...)
注:ADD是代表新增一字段,字段位置在所有列后面(partition列前),REPLACE则是表示替换表中所有字段
实操案例
- 查询表结构
hive> desc dept_partition;
- 添加列
hive (default)> alter table dept_partition add columns(deptdesc string);
- 查询表结构
hive> desc dept_partition;
- 更新列
hive (default)> alter table dept_partition change column deptdesc desc int;
- 查询表结构
hive> desc dept_partition;
- 替换列
hive (default)> alter table dept_partition replace columns(deptno string, dname string, loc string);
- 查询表结构
hive> desc dept_partition;
删除表
hive (default)> drop table dept_partition;
简书:https://www.jianshu.com/u/0278602aea1d
CSDN:https://blog.csdn.net/u012387141