Hive中的表操作

Hive中的表的基本操作。如下。

首先创建一个雇员表和部门表

  • 雇员表
    create table emp(
    empno int,
    ename string,
    job string,
    mgr int,
    hiredate string,
    sal double,
    comm double,
    deptno int
    )
    row format delimited fields terminated by ‘\t’;
    ‘\t’:表示制表符(tab)

  • 部门表
    create table dept(
    deptno int,
    dname string,
    loc string
    )
    row format delimited fields terminated by ‘\t’;

    《Hive中的表操作》 deptAndEmp

  • 加载数据到表
    说明:加载的txt文本数据的字符格式必须是UTF-8格式
    加载数据命令:
    load data local inpath ‘/opt/datas/emp.txt’ overwrite into table emp;
    load data local inpath ‘/opt/datas/dept.txt’ overwrite into table dept;

《Hive中的表操作》

  • 根据子查询创建表
    create table if not exists default.dept_cats as select * from dept;

    《Hive中的表操作》

表操作

  • 删除表中的数据
    truncate table dept_cats ;

    《Hive中的表操作》

  • 创建表
    1、创建一个dept_like表
    create table if not exists default.dept_like
    like default.dept;

    《Hive中的表操作》

2、把dept_like表重新命名为dept_like_rename
alter table dept_like rename to dept_like_rename;

《Hive中的表操作》 rename

  • 删除一张表
    命令:drop table if exitis dept_like_rename;

    《Hive中的表操作》

    原文作者:志辉聊码
    原文地址: https://www.jianshu.com/p/7836dfd0d4b5
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞