管理表 内部表也称之为MANAGED_TABLE; 默认存储在/user/hive/warehouse下,也可以通过location指定; 删除表时,会删除表数据以及元数据;
外部表 外部表称之为EXTERNAL_TABLE; 在创建表时可以自己指定目录位置(LOCATION); 删除表时,只会删除元数据不会删除表数据;
创建外部表
create external table if not exists 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';
不用put数据就可以查询数据,因为表所在的目录下有个emp.txt 文件。
说明:只需要创建表结构,不需要put数据。因为数据已经存在。
就是你把emp_ext2表删除掉数据还是会存在的,这
就是外部表。80%的企业都是使用这种方式进行数据管理和使用的。