修改已经存在的表:alter table
Alter table语句允许用户改变现有表的结构。用户可以增加列/分区,表本身重命名。1)增加分区Add Partitions:ALTER TABLE table_name ADD partition_spec [ LOCATION 'location1']partition_spec [ LOCATION 'location2' ]其中partition_spec的格式为:PARTITION (partition_col =partition_col_value, partition_col =partiton_col_value, ...)用户可以用ALTER TABLE ADD PARTITION来向一个表中增加分区。当分区名是字符串时加引号。alter table test_partition add partition (dt='2012-03-06')location'/home/zhangxin/hive/test_hive.txt';
2)删除分区drop Partition:ALTER TABLE table_name DROP partition_spec, partition_spec,...用户可以用ALTER TABLE DROP PARTITION来删除分区。分区的元数据和数据将被一并删除。alter table test_partition drop partition (dt='2012-03-06')
3)对表进行重命名rename to:ALTER TABLE table_name RENAME TO new_table_name这个命令可以让用户为表更名。数据所在的位置和分区名并不改变。换而言之,老的表名并未“释放”,对老表的更改会改变新表的数据。alter table test_partition rename to new_test_partition;