修改
列的名稱、類型、位置、注釋
hive>ALTER TABLE t3 CHANGE COLUMN old_name new_name String [COMMENT '...'] [AFTER column2];
實例
hive (zmgdb)> alter table t1 change column car sarly int after office;
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Unable to alter table. The following columns have types incompatible with the existing columns in their respective positions :
sarly
----字段car是string類型與int類型不兼容,不能強轉。
hive (zmgdb)> alter table t1 change column car sarly string after office;
OK
Time taken: 0.132 seconds
hive (zmgdb)> desc t1;
OK
col_name ? ? ? ?data_type ? ? ? comment
name ? ? ? ? ? ? ? ? ? ?string ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
address ? ? ? ? ? ? ? ? string ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
company ? ? ? ? ? ? ? ? string ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
office ? ? ? ? ? ? ? ? ?string ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
sarly ? ? ? ? ? ? ? ? ? string ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Time taken: 0.035 seconds, Fetched: 5 row(s)
hive (zmgdb)>?
增加
hive>ALTER TABLE t3 ADD COLUMNS(gender int);columns:復數,可以多個
沒有刪除列的命令: 刪除列后,會導致數據解析出問題