Hive学习笔记(7)- Hive 外部表

1 Hive 表的类型

1.1 默认都是 管理表(内部表)

  • 内部表删除表时,会删除表数据和元数据;
  • 默认存在 /user/hive/warehouse,可以通过 location 指定

desc formatted dept;
在这里插入图片描述

1.2 创建外部表

  • 删除表时,只会删除元数据,不会删除表数据(在 HDFS);
  • 创建表时可以自己指定目录位置
  • 企业大部分用的外部表
create external table if not exists default.emp_ext(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
) row format delimited fields terminated by '\t';

desc formatted emp_ext;
在这里插入图片描述

1.2.1 创建外部表并且指定位置

将数据和表放到 HDFS 用一个目录,数据会自动导入

  • hive (default)> dfs -mkdir -p /user/hive/warehouse/emp_ext2;
  • `hive (default)> dfs -put /home/hadoop/emp.txt /user/hive/warehouse/emp_ext2;
create external table if not exists default.emp_ext2(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
) row format delimited fields terminated by '\t'
location '/user/hive/warehouse/emp_ext2';

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值