2020-03 hive基礎(chǔ)命令

1.進(jìn)入hive數(shù)據(jù)庫: hive

2.查看hive中的所有數(shù)據(jù)庫:show databases;

3.用default數(shù)據(jù)庫: use default;

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

5.查詢表結(jié)構(gòu):desc? 表名

6.查詢表數(shù)據(jù):select * from 表名;

7.創(chuàng)建數(shù)據(jù)庫: create schema 庫名;

8.驗(yàn)證數(shù)據(jù)庫表:show databases;

9.刪除數(shù)據(jù)庫:

1)? drop databases if exists 庫名;

2)? drop schema 庫名;

全部刪除相應(yīng)的表在刪除數(shù)據(jù)庫之前(關(guān)聯(lián)刪除): drop databases if exists? 庫名cascade

10.創(chuàng)建表employee:

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

> comment 'enmployee details'? # 表描述

> row format delimited? ? ? ? ? ? ? ? # 設(shè)置行格式分隔開頭語句

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

> lines terminated by '\n'? ? ? # 數(shù)據(jù)分割采用 '\n'

> stored as textfile;? ? ? ? ? ? ? ? ? ? ? # 存儲為文本文件(結(jié)束語)

11.如果增加分區(qū)必須在創(chuàng)建表的時候就創(chuàng)建分區(qū),不然就會報(bào)錯,

? ? 創(chuàng)建分區(qū)的命令>partition by ‘根據(jù)哪個字段分區(qū)’

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.添加數(shù)據(jù)到表中(!!!? hive只支持插入不支持修改和刪除)

load data local inpath '/usr/hadoop/sample.txt'? ? # 讀取本地路徑的數(shù)據(jù)

overwrite into tableemployee# 覆蓋寫入employee表格中

【如果table是個分區(qū)表則必須在hql中指定分區(qū)】

overwrite into tableemplyeepartition(year=2020)

【插入表數(shù)據(jù)】

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的數(shù)據(jù)類型從float改為double:

alter tableempsalary salary double;

15.刪除表:? drop tableemp;

16.創(chuàng)建視圖: create view empview as

select * fromempwhere salary >1000;

17.不同類型的連接:

join

left outer join

right outer join

full outer join

18.創(chuàng)建外部表:用external關(guān)鍵字

create external table outsidetable

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

? ? ? ? # 描述? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 描述

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容