现有分区表table1表,表结构如下:
+--------------------------+-----------------------+-----------------------+--+
| col_name | data_type | comment |
+--------------------------+-----------------------+-----------------------+--+
| userid | string | 用户ID |
| birth | string | 用户生日 |
| age | string | 用户年龄 |
| gender | string | 用户性别 |
| pt | string | 用户注册时间 |
| | NULL | NULL |
| # Partition Information | NULL | NULL |
| # col_name | data_type | comment |
| | NULL | NULL |
| pt | string | 用户注册时间 |
1、创建结构一样的表,但不复制数据
--想创建一个和表table1结构一样的table2:
create table tmp_db.tmp_table2 like tmp_db.tmp_user_info;
2、修改表名
--将table1的表名修改为table2:
alter table table1 rename to table2;
3、修改字段名或注释
--将table1的的字段useid修改为user:
alter table table1 change userid user string comment'用户ID';
--修改后的字段如下
+-----------+------------+----------+--+
| col_name | data_type | comment |
+-----------+------------+----------+--+
| user | string | 用户ID |
4、添加、修改表注释
--将table1的表注释修改为'用户基础信息':
alter table table1 tblproperties(comment='用户基础信息');
5、删除表分区
--删除日期为2021-01-17的分区:
alter table table1 drop partition(pt='2021-01-17');
6、新增字段
--新增phone字段:
alter table table add columns(phone string comment'电话');
--此时表结构如下:
+--------------------------+-----------------------+-----------------------+--+
| col_name | data_type | comment |
+--------------------------+-----------------------+-----------------------+--+
| userid | string | 用户ID |
| birth | string | 用户生日 |
| age | string | 用户年龄 |
| gender | string | 用户性别 |
| phone | string | 电话 |
| pt | string | 用户注册时间 |
| | NULL | NULL |
| # Partition Information | NULL | NULL |
| # col_name | data_type | comment |
| | NULL | NULL |
| pt | string | 用户注册时间 |