1.查看表的详细属性信息 【desc formatted】
hive> desc formatted 表名;
OK
2.重命名表 【Rename To】
对于内部表,除了更新表的元数据之外,还对表的目录名称进行修改。
对于外部表,这个操作只更新元数据,但不会更改存放数据的目录名称。
hive> alter table 旧表名 rename to 新表名;
OK
3.添加新列 【Add Column】
hive> alter table 表名
> add columns(id int); --增加id列,类型int
OK
4.修改列名及对应类型 【Change Column】
hive> alter table t081901
> change column te --要进行修改的列名
> temperature int; --修改后的列名和数据类型
OK
5.替换【重置】表的列名和类型 【Replace Column】
这个操作其实是将原有的列删除,然后再添加新的指定的列
hive> alter table student
> replace columns( --replace columns替换数据列
> age int,
> name string);
OK
6.创建一个模式一样的新表 【Like】
CREATE TABLE new_table LIKE existing_table;
6.1.清空表【delete和truncate】
Hive中不支持delete table T_Name操作。
Hive中支持 truncate table T_Name操作。对于分区表,它是将各个分区下面的数据文件删除,但是分区的目录还存在。相当于执行了以下命令:hive > dfs -rmr /user/hive/warehouse/my_table;
7.增加分区【Add Partition】
hive> alter table logs add
> partition(date=‘2015-01-03’,country=‘USA’) --分区
> location ‘/user/hive/warehouse/logs/date=2015-01-03/country=USA’ --分区路径
hive> alter table logs add
> partition(date=‘2015-01-03’,country=‘USA’); --新增分区,不指定路径
OK
8.删除分区【Drop Partition】
hive> alter table logs DROP partition(date=‘2015-01-03’); --直接删除一级分区
Dropped the partition date=2015-01-03/country=USA