hive对表的增删改查


前言

本文主要介绍hive中对表的改动基本内容




一、修改表

hive的使用中经常会有修改表的操作,本文简单的介绍hive表的修改




二、具体操作




1.重命名表

create table table_a(id int); //创建表table_a;
alter table table_a rename to table_b;//重命名table_a为table_b




2.更新修改列

alter table table_a change column id student_id int;//将列名id修改为student_id,类型不变
alter table table_a change column student_id student_id string;//不修改列名,仅修改列的类型为string
desc table_a;//查询表的结构信息
alter table table_a add columns(name string)//向table_a表中新增一列,列名为name,类型为string
alter table table_a change name name string first;//调整列name在最前面
alter table table_a change name name string after student_id;//将name更新到指定列的后面
alter table table_a replace columns(age int);//替换所有的列
drop table table_a;//删除表

本文总结的是hive中对表的基本操作,分区表跟桶下期再进行总结


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hive和HBase是两个不同的数据存储系统,它们的查询语言也不一样。Hive使用HQL(Hive Query Language)来查询数据,而HBase使用Java API或HBase Shell来查询数据。 下面是Hive中的常见操作示例: 1. 查询数据 ``` SELECT * FROM table_name; ``` 2. 插入数据 ``` INSERT INTO TABLE table_name VALUES (value1, value2, ...); ``` 3. 更新数据 ``` UPDATE table_name SET column_name = new_value WHERE condition; ``` 4. 删除数据 ``` DELETE FROM table_name WHERE condition; ``` 下面是HBase中的常见操作示例: 1. 查询数据 使用Java API: ``` Get get = new Get(Bytes.toBytes("row_key")); Result result = table.get(get); ``` 使用HBase Shell: ``` get 'table_name', 'row_key' ``` 2. 插入数据 使用Java API: ``` Put put = new Put(Bytes.toBytes("row_key")); put.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_name"), Bytes.toBytes("value")); table.put(put); ``` 使用HBase Shell: ``` put 'table_name', 'row_key', 'column_family:column_name', 'value' ``` 3. 更新数据 使用Java API: ``` Put put = new Put(Bytes.toBytes("row_key")); put.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_name"), Bytes.toBytes("new_value")); table.put(put); ``` 使用HBase Shell: ``` put 'table_name', 'row_key', 'column_family:column_name', 'new_value' ``` 4. 删除数据 使用Java API: ``` Delete delete = new Delete(Bytes.toBytes("row_key")); delete.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_name")); table.delete(delete); ``` 使用HBase Shell: ``` delete 'table_name', 'row_key', 'column_family:column_name' ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值