修改表
重命名表
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;