2020-03 hive基础命令

1.进入hive数据库: hive

2.查看hive中的所有数据库:show databases;

3.用default数据库: use default;

4.查看所有的表:show  tables;

5.查询表结构:desc  表名

6.查询表数据:select * from 表名;

7.创建数据库: create schema 库名;

8.验证数据库表:show databases;

9.删除数据库:

1)  drop databases if exists 库名;

2)  drop schema 库名;

全部删除相应的表在删除数据库之前(关联删除): drop databases if exists  库名cascade

10.创建表employee:

create table if existsemployee (eid int,name String, salary String, deestation String)

> comment 'enmployee details'  # 表描述

> row format delimited                # 设置行格式分隔开头语句

> fields terminated by '\t'      # 字段分割采用 Tab 分割

> lines terminated by '\n'      # 数据分割采用 '\n'

> stored as textfile;                      # 存储为文本文件(结束语)

11.如果增加分区必须在创建表的时候就创建分区,不然就会报错,

    创建分区的命令>partition by ‘根据哪个字段分区’

create tableemployee (id int,name String, salary String)

> partition by (year int)

> row format delimited

> field terminated by '\t'

> lines terminater by '\n'

> stroed as textfile;

(文件格式在hive中有三种: textfile、Sequencefile 序列化文件、Rcfile。)

12.添加数据到表中(!!!  hive只支持插入不支持修改和删除)

load data local inpath '/usr/hadoop/sample.txt'    # 读取本地路径的数据

overwrite into tableemployee# 覆盖写入employee表格中

【如果table是个分区表则必须在hql中指定分区】

overwrite into tableemplyeepartition(year=2020)

【插入表数据】

insert into employee(eid, name) values(1000,'wsc')

13.重命名表名:  alter tableemployeerename toemp

14. 修改表

1) 修改emp表中字段name为ename:

alter tableempchange name ename String

2) 修改emp表中字段salary的数据类型从float改为double:

alter tableempsalary salary double;

15.删除表:  drop tableemp;

16.创建视图: create view empview as

select * fromempwhere salary >1000;

17.不同类型的连接:

join

left outer join

right outer join

full outer join

18.创建外部表:用external关键字

create external table outsidetable

(name string comment 'name value', addr sting comment 'addr value')

        # 描述                                                    # 描述

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容