HIVE建内部表语句

create table dll102.sougou
(id string,pwd string,name string,count int,seqno int,address string)
row format delimited fields terminated by '\t' ;

创建字段中含有数组类型,对象类型的表,并查询特殊字段

外部表默认 存在HDFS下的  ‘/user/hadoop/指定路径’

 将本地文件加载到HIVE

load data local inpath '/home/hadoop/sgtest' into table sougou;

 查看表结构

desc formatted  emp;[table_name];

常用SQL语句

// 创建内部表 student
create table student(id int, name string, sex string, age int, department string)
row format delimited fields terminated by ',' //行分隔符用 lines
stored as textfile; // 从本地导入数据
load data local inpath '/home/hadoop/student.txt' into table student; // 查询数据
select id, name, sex, age, department from student; // 创建一个external表
create external table ext_student(id int, name string, sex string, age int, department string)
row format delimited fields terminated by ','
location '/ext_student'; // 导入数据
hadoop fs -put student.txt /ext_student;
load data local inpath '/home/hadoop/mingxing.txt' into table ext_student; // 查询数据
select id, name ,sex, age , department from ext_student; // 创建内部表引用外部路径
create table mng_student(id int, name string, sex string, age int, department string)
row format delimited fields terminated by ','
location '/ext_student'; // 创建分区表
create table ptn_student(id int, name string, sex string, age int, department string)
partitioned by(code string)
row format delimited fields terminated by ','; // 往分区表导入数据
load data local inpath '/home/hadoop/student.txt' into table ptn_student partition(code='');
load data local inpath '/home/hadoop/student.txt' into table ptn_student1 partition(code=''); //Hive表数据导出到HDSF
export table table_name to '/test/xx'; //Hive查询结果的导出
insert overwrite local directory '/opt/bigdata/export/student' select * from student;
insert overwrite local directory '/opt/bigdata/export/student' row format delimited fields terminated by ',' select * from student;

有local指的是导出到本地  ,没有local 导出到HDFS
// 创建多字段分区表
create table ptn_student1(id int, name string, sex string, age int, department string)
partitioned by(code string, province string)
row format delimited fields terminated by ','; // 往多分区表导入数据,需指定两个分区字段值
load data local inpath '/home/hadoop/student.txt'
into table ptn_student1 partition(code='', province='beijing');
load data local inpath '/home/hadoop/student.txt'
into table ptn_student1 partition(code='', province='tianjing');
load data local inpath '/home/hadoop/student.txt'
into table ptn_student1 partition(code='kk', province='tianjing'); // 创建分桶表
create table bck_student(id int, name string, sex string, age int, department string)
clustered by(department) into 4 buckets
row format delimited fields terminated by ','; // 重命名表
alter table student rename to studentss; // 修改表的字段
alter table studentss add columns(abc string, efg int); // 删除表的字段,有一些问题。drop字段有问题。不确定能不能执行成功
alter table studentss drop column efg; // 修改表的字段
alter table studentss change abc code int; // 修改表的字段,并且改变字段的位置
alter table studentss change efg province string after name; // 替换所有字段
alter table studentss replace columns(id int, name string, sex string ,
age int , department string); // 删除表
drop table bck_student;
drop table if exists bck_student; // 添加分区
alter table ptn_student add partition(code='');
alter table ptn_student add partition(code='') partition(code=''); // 删除分区
alter table ptn_student drop partition(code=''); // insert ... select .....
insert into table student select id, name, sex, age, department from studentss where department = 'MA'; // 以下两句操作是为多重插入准备两张表
create table student11(id int, name string)
row format delimited fields terminated by ','
stored as textfile; create table student22(sex string, age int, department string)
row format delimited fields terminated by ','
stored as textfile; // 多重插入
from studentss
insert into table student11 select id, name
insert into table student22 select sex, age, department; // 静态分区插入
load data local inpath 'student.txt' into table ptn_student partition(code=''); // 动态分区插入
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
insert into table d_student partition(age) select id, name, sex, department,age from studentss; // 创建一个分区表,为上面的动态分区做准备的
create table d_student(id int, name string, sex string ,department string)
partitioned by(age int)
row format delimited fields terminated by ','; // CTAS
create table my_student as select id, name , sex, age, department from studentss; // like
create table like_student like studentss; // insert导出hive表数据到本地
insert overwrite local directory '/home/hadoop/myoutput'
select id, name, sex, age, department from studentss;

HIVE常用SQL语句及语法的更多相关文章

  1. 【知识库】-数据库_MySQL常用SQL语句语法大全示例

    简书作者:seay 文章出处: 关系数据库常用SQL语句语法大全 Learn [已经过测试校验] 一.创建数据库 二.创建表 三.删除表 四.清空表 五.修改表 六.SQL查询语句 七.SQL插入语句 ...

  2. oracle常用SQL语句(汇总版)

    Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, ...

  3. 常用SQL语句(增删查改、合并统计、模糊搜索)

    转自:http://www.cnblogs.com/ljianhui/archive/2012/08/13/2695906.html 常用SQL语句 首行当然是最基本的增删查改啦,其中最重要的是查. ...

  4. GP数据库 常用SQL语句

    GP数据库 常用SQL语句 --1,查看列名以及类型 select upper(column_name) ,data_type from information_schema.columns wher ...

  5. Oracle数据库常用Sql语句大全

    一,数据控制语句 (DML) 部分 1.INSERT  (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, 字段名2, ……) VALUES ( 值1, 值2, ……); INSE ...

  6. 经典MSSQL语句大全和常用SQL语句命令的作用

    下列语句部分是Mssql语句,不可以在access中使用. SQL分类: DDL类型包括数据库.表的创建,修改,删除,声明—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML类 ...

  7. mysql 常用 sql 语句 - 快速查询

    Mysql 常用 sql 语句 - 快速查询 1.mysql 基础 1.1 mysql 交互         1.1.1 mysql 连接             mysql.exe -hPup    ...

  8. 常用SQL语句大全

    一些常用SQL语句大全   一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql se ...

  9. DB2常用sql语句

    转 DB2 提供了关连式资料库的查询语言sql(structured query language),是一种非常口语化.既易学又易懂的语法.此一语言几乎是每个资料库系统都必须提供的,用以表示关连式的操 ...

随机推荐

  1. 牛客练习赛48 C,D,E

    C 小w的糖果 题意:3种操作,第一种是使pos右边的数全部+1,第二种是pos右边的数依次+k(k从1开始递增),第三种是pos右边的数依次+k^2(k从1开始递增). 解法:第一种我们很容易想到差 ...

  2. Codeforces 19E&BZOJ 4424 Fairy(好题)

    日常自闭(菜鸡qaq).不过开心的是看了题解之后1A了.感觉这道题非常好,必须记录一下,一方面理清下思路,一方面感觉自己还没有完全领会到这道题的精髓先记下来以后回想. 题意:给定 n 个点,m 条边的 ...

  3. Codeforces 1105E 最大独立集 状态DP 中途相遇法

    题意:你有一个字符串, 有两种操作,一种是改变字符串,一种是某个用户询问这个字符串,如果一个用户每次查询字符串的时候都是他的用户名,他就会高兴.问最多有多少个用户会高兴? 题意:容易发现,在两个1操作 ...

  4. 基于.Net4.0实现 ToastNotification

    基于.Net4.0实现 ToastNotification Windows更新之路的特色之一就是消息提示由气泡变成了通知窗口,效果简直不要太好.最近公司有这方面的需求,需要在xp,win7系统上给出提 ...

  5. leetcode-12双周赛-1243-数组变换

    题目描述: 自己的提交: class Solution: def transformArray(self, arr: List[int]) -> List[int]: if len(arr) & ...

  6. CTSC2019

    (upd:随机立方体AC) 太菜了只会部分分.以后慢慢补坑吧…… 随机立方体: 30分: 正常人都能想到的的转移状态(我的确是弱智),从大往小填数,记录有多少个极大值点和三个方向上各占了多少.转移可以 ...

  7. Spring 容器初始化方法

    Resource resource = new ClassPathResource("/bean.xml");         resource = new FileSystemR ...

  8. (转)微信,QQ这类IM app怎么做——谈谈Websocket

    转:http://www.cocoachina.com/ios/20160527/16482.html 前言 关于我和WebSocket的缘:我从大二在计算机网络课上听老师讲过之后,第一次使用就到了毕 ...

  9. 天梯L3-003. 社交集群——并查集

    在社交网络平台注册时,用户通常会输入自己的兴趣爱好,以便找到和自己兴趣相投的朋友.有部分兴趣相同的人们就形成了“社交集群”.现请你编写程序,找出所有的集群. 输入格式: 输入的第一行给出正整数N(&l ...

  10. Win7下使用DbgPrint

    在Win7下默认DbgPrint输出信息后,使用DbgView看不到内容. 新建一个reg文件,双击导出就行了. Windows Registry Editor Version 5.00 [HKEY_ ...