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. Lambda select 动态字段

    直接上代码 //测试数据 public static List<User> myList = new List<User>() { , Name=,IsChild=false} ...

  2. node.js提供的服务器live-server的使用

    安装node.js的版本控制工具nvm,在终端中执行 curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/instal ...

  3. web.xml中配置——解决post乱码

    <!-- 解决post乱码 --> <filter> <filter-name>CharacterEncodingFilter</filter-name> ...

  4. Linux下Golang Socket编程原理分析与代码实现

    在POSIX标准推出后,socket在各大主流OS平台上都得到了很好的支持.而Golang是自带Runtime的跨平台编程语言,Go中提供给开发者的Socket API是建立在操作系统原生Socket ...

  5. JMeter 常用网站

    1.jmeter插件 https://blog.csdn.net/weixin_39430584/article/details/80947093 http://www.doc88.com/p-214 ...

  6. vue v-modle修饰符.number .trim

    语法糖: 在不影响功能的情况下,添加某种方法实现同样的效果,从而方便程序开发. .number:可以将输入转换成Number类型,否则虽然输入的是数字,但它的类型其实是String. .trim:自动 ...

  7. 冲刺$\mathfrak{CSP-S}$集训模拟赛总结

    开坑.手懒并不想继续一场考试一篇文. 既没必要也没时间侧边栏的最新随笔题解反思相间也丑 而且最近越来越懒了竟然都不写题解了……开坑也是为了督促自己写题解. 并不想长篇大论.简要题解也得写啊QAQ. 目 ...

  8. 【Codeforces Round #429 (Div. 2) C】Leha and Function

    [Link]:http://codeforces.com/contest/841/problem/C [Description] [Solution] 看到最大的和最小的对应,第二大的和第二小的对应. ...

  9. 拆边+BFS队列骚操作——cf1209F

    这个拆边+队列操作实在是太秒了 队列头结点存的是一个存点集的vector,1到这个点集经过的路径权值是一样的,所以向下一层拓展时,先依次走一遍每个点的0边,再走1边...以此类推,能保证最后走出来的路 ...

  10. Luogu P2042 [NOI2005]维护数列

    题目描述 请写一个程序,要求维护一个数列,支持以下 6 种操作:(请注意,格式栏 中的下划线' _ '表示实际输入文件中的空格) 输入输出格式 输入格式: 输入文件的第 1 行包含两个数 N 和 M, ...