基本语法:
ALTER TABLE name RENAME TO new_name
ALTER TABLE name ADD COLUMNS (col_spec[, col_spec ...])
ALTER TABLE name DROP [COLUMN] column_name
ALTER TABLE name CHANGE column_name new_name new_type
ALTER TABLE name REPLACE COLUMNS (col_spec[, col_spec ...])
(col_spec[, col_spec ...])
ALTER TABLE name DROP [COLUMN] column_name
ALTER TABLE name CHANGE column_name new_name new_type
ALTER TABLE name REPLACE COLUMNS (col_spec[, col_spec ...])
refer: https://www.yiibai.com/hive/hive_alter_table.html
自己实验:
1. alter table d_extra.dm_usr_mxdai_risk_analysis add columns(test1 int, test2 int); ------works
desc d_extra.dm_usr_mxdai_risk_analysis;
可以看出新字段已经添加成功
1.1. alter table d_extra.dm_usr_mxdai_risk_analysis add column test1 int; ------doesn't work
2. alter table d_extra.dm_usr_mxdai_risk_analysis drop column test1; -----doesn't work
报错:
Error: Error while compiling statement: FAILED: ParseException line 1:52 mismatched input 'column' expecting PARTITION near 'drop' in drop partition statement (state=42000,code=40000)
是不是只能drop partition 而不能drop column??
3. alter table d_extra.dm_usr_mxdai_risk_analysis change test1 risk_1_138 string; ------works
Hive不支持行级插入操作、更新操作和删除操作。
eg1. delete from tmp.pid_free_2_paid_ana_time where pre_free_pack_id = 104
报错
eg2. truncate
delect:用于删除特定行条件,你可以从给定表中删除所有的行????
TRUNCATE:truncate用于删除所有的行,这个行为在Hive元存储删除数据是不可逆的
DROP:删除hive中的表
truncate 不能删除外部表!因为外部表里的数据并不是存放在Hive Meta store中
truncate:
truncate table table_name;
例子:
truncate table employees;
ref:
https://www.bbsmax.com/A/q4zV0qQb5K/