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. 停止node进程

    运行vue-cli项目的时候经常出现端口号占用,npm run dev报错的信息, 此时可通过任务管理器粗暴的杀死node进程,也可以通过cmd检测占用某个端口的程序,进而杀死该进程,步骤如下: 1. ...

  2. Spring事务管理-传播行为-隔离级别

    事务是逻辑上的一组操作,这组操作要么全部成功,要么全部失败. 事务的特性:ACID 原子性:事务是一个不可分割的工作单位,事务中的操作要么都发生,要么都不发生 一致性:事务前后数据的完整性约束保持一致 ...

  3. vue之全局自定义组件

    在项目开发中,往往需要使用到一些公共组件,比如,弹出消息.面包屑或者其它的组件,为了使用方便,将其以插件的形式融入到vue中,以面包屑插件为例: 1.创建公共组件MyBread.vue <tem ...

  4. koa-artTemplate 的使用

    1.父页面 <html> <head> <meta charset="UTF-8"> <title>我的音乐</title&g ...

  5. Tomcat---概述

    1.Tomcat  是  一个  免费.开源  的 web应用服务器: 属于  轻量级  应用服务器,在中小型系统.并发量不大的情况下  被广泛使用: 2.Tomcat 是  Apache下的核心项目 ...

  6. Python装饰器使用技巧

    装饰器 装饰器是程序开发中经常会用到的一个功能,用好了装饰器,开发效率如虎添翼,所以这也是Python面试中必问的问题,但对于好多初次接触这个知识的人来讲,这个功能有点绕,自学时直接绕过去了,然后面试 ...

  7. 区别|Pandas-qcut( )与cut( )的区别

    https://blog.csdn.net/starter_____/article/details/79327997

  8. TxtUtil

    /** *包名:cn.yufu.utils *描述:package cn.yufu.utils; */ package cn.yufu.utils; import java.io.BufferedRe ...

  9. 二维差分前缀和——cf1202D(好题)

    直接枚举每个点作为左上角是可以做的,但是写起来较麻烦 有一种较为简单的做法是对一列或一行统计贡献 比如某一行的B存在的区间是L,R那么就有三种情况 1.没有这样的区间,即一行都是W,此时这行对答案的贡 ...

  10. The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)

    B. super_log 题意:研究一下就是求幂塔函数 %m的值. 思路:扩展欧拉降幂. AC代码: #include<bits/stdc++.h> using namespace std ...