Hive的DDL資料定義(二)表的修改和刪除
阿新 • • 發佈:2018-12-02
重命名錶
語法
ALTER TABLE table_name RENAME TO new_table_name
案例
hive (hive)> 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則是表示替換表中所有欄位。
新增列
alter table dept_partition2 add columns(deptdesc string);
修改列
alter table dept_partition2 change column deptdesc desc int;
替換列
alter table dept_partition2 replace columns(dept string,dname string,loc int);
替換的只是元資料的資訊,實際資料沒有變化
注:每次操作都可以 desc + 表名查詢詳情
刪除表
hive (hive)> drop table dept_partition2;