Hive的表操作(表名的修改,列的修改)

关于表的修改命令如下:包括更改表名,给表增加字段,查看表的信息,表字段的替换

1,表名的修改:
0: jdbc:hive2://hadoop108:10000> show tables;
+-----------+--+
| tab_name  |
+-----------+--+
| stu1      |
| stu2      |
| stu3      |
| stu_ex1   |
| stu_par   |
| stu_par2  |
+-----------+--+

0: jdbc:hive2://hadoop108:10000> alter table stu_par rename to stu_par1;

0: jdbc:hive2://hadoop108:10000> show tables;
+-----------+--+
| tab_name  |
+-----------+--+
| stu1      |
| stu2      |
| stu3      |
| stu_ex1   |
| stu_par1  |
| stu_par2  |
+-----------+--+


2,给stu1增加score字段:
0: jdbc:hive2://hadoop108:10000> desc stu1;
OK
+-----------+------------+----------+--+
| col_name  | data_type  | comment  |
+-----------+------------+----------+--+
| id        | int        |          |
| name      | string     |          |
+-----------+------------+----------+--+

0: jdbc:hive2://hadoop108:10000> alter table stu1 add columns(score string);
OK
No rows affected (0.185 seconds)
0: jdbc:hive2://hadoop108:10000> desc stu1;
OK
+-----------+------------+----------+--+
| col_name  | data_type  | comment  |
+-----------+------------+----------+--+
| id        | int        |          |
| name      | string     |          |
| score     | string     |          |
+-----------+------------+----------+--+
3 rows selected (0.093 seconds)

3,修改score的类型为double:
0: jdbc:hive2://hadoop108:10000> desc stu1;
+-----------+------------+----------+--+
| col_name  | data_type  | comment  |
+-----------+------------+----------+--+
| id        | int        |          |
| name      | string     |          |
| score     | string     |          |
+-----------+------------+----------+--+

0: jdbc:hive2://hadoop108:10000> alter table stu1 change column score score double;
0: jdbc:hive2://hadoop108:10000> desc stu1;
+-----------+------------+----------+--+
| col_name  | data_type  | comment  |
+-----------+------------+----------+--+
| id        | int        |          |
| name      | string     |          |
| score     | double     |          |
+-----------+------------+----------+--+

4,将score放置于id之后:
0: jdbc:hive2://hadoop108:10000> alter table stu1 change column score score double after id;
OK
No rows affected (0.175 seconds)
0: jdbc:hive2://hadoop108:10000> desc stu1;
+-----------+------------+----------+--+
| col_name  | data_type  | comment  |
+-----------+------------+----------+--+
| id        | int        |          |
| score     | double     |          |
| name      | string     |          |
+-----------+------------+----------+--+

5,将所有的列替换成为(id int,name,string)
0: jdbc:hive2://hadoop108:10000> desc stu1;
OK
+-----------+------------+----------+--+
| col_name  | data_type  | comment  |
+-----------+------------+----------+--+
| id        | int        |          |
| score     | double     |          |
| name      | string     |          |
+-----------+------------+----------+--+
3 rows selected (0.079 seconds)
0: jdbc:hive2://hadoop108:10000> alter table stu1 replace columns(id int,name string);
OK
No rows affected (0.15 seconds)
0: jdbc:hive2://hadoop108:10000> desc stu1;
OK
+-----------+------------+----------+--+
| col_name  | data_type  | comment  |
+-----------+------------+----------+--+
| id        | int        |          |
| name      | string     |          |
+-----------+------------+----------+--+

 

你可能感兴趣的:(bigData,Hive,Hive)