hive 基础命令demo

本文介绍了Hive的基础命令,包括创建新表、分区表及视图,删除数据库和表,查询表信息,加载数据到Hive,以及修改表结构等操作。详细内容包括:创建表、删除表、查询数据库信息、加载数据、修改表名和字段,以及时间格式转换等实用技巧。
摘要由CSDN通过智能技术生成

*命令wiki超链接:*https://cwiki.apache.org/confluence/display/Hive/LanguageManual

创建

  • 1.创建新表

     create table t_hive (
     a int
     , b int
     , c int) 
     row format delimited fields terminated by '\t';
    
  • 2.创建分区表

    drop table if exists t_hft;
    create table t_hft(
    securityid string,
    tradetime string,
    preclosepx double
    ) partitioned by (tradedate int)
    row format delimited fields terminated by ',';
    
  • 3.创建视图

    create view v_hive as select a,b from t_hive;
    

删除

  1. 删除数据库(级联删除)

    drop database if exists db_name;
    
  2. 删除表

    drop table if exists tbname ;
    
  3. 删除表数据

    truncate table tablename;
    
  4. 修改表名

    alter table tbname rename to newtbname
    
  5. 删除分区数据

    alter table dbname.tablename drop if exists partition (dtd='20180724');
    

查询

  1. 查看数据库信息

    desc database extended dbname;
    
  2. 模糊查询表名

    show tables '*t*';
    
  3. 查询表结构

    desc formatted table_name
    
  4. 查看表分区

    show partitions tbname;
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值