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. MOS管知识大集

    MOS管 增强型:就是UGS=0V时漏源极之间没有导电沟道,只有当UGS>开启电压(N沟道)或UGS<开启电压(P沟道)才可能出现导电沟道.耗尽型:就是UGS=0V时,漏源极之间存在导电沟 ...

  2. [转载]MinGW安装过程

    本文转自https://blog.csdn.net/my_wade/article/details/46941645 MinGW安装过程 一. 下载 MinGW官网下载地址:http://source ...

  3. shell脚本进行设置启动/关闭

    vi /etc/init.d/confluence ----------------------------- #!/bin/bash# chkconfig: 2345 85 15# Provides ...

  4. 转载 如何理解API,API 是如何工作的

    本文转载于https://blog.csdn.net/cumtdeyurenjie/article/details/80211896 感谢作者 仁杰兄 大家可能最近经常听到 API 这个概念,那什么是 ...

  5. 使用raise语句抛出异常

    #_author:来童星#date:2019/12/18def division(): num1=int(input('请输入被除数:')) num2=int(input('请输入除数:')) if ...

  6. MySQL常用操作2

    MySQL常用操作2 判断函数 IF(expr, value1, value2)  --  如果表达式expr为true,则返回value1,否则返回value2 IFNULL(value1, val ...

  7. input select 值得绑定与获取

    <div style="margin-top:100px"> <!--Input 值得绑定--> <div id="app20"& ...

  8. jqery基础知识实例(二)

    无缝滚动 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  9. PHP ftp_exec() 函数

    定义和用法 ftp_exec() 函数请求在 FTP 服务器上执行一个程序或命令. 如果成功,该函数返回 TRUE.如果失败,则返回 FALSE. 语法 ftp_exec(ftp_connection ...

  10. I/O复用select 使用简介

    一:五种I/O模型区分: 1.阻塞I/O模型      最流行的I/O模型是阻塞I/O模型,缺省情形下,所有套接口都是阻塞的.我们以数据报套接口为例来讲解此模型(我们使用UDP而不是TCP作为例子的原 ...