hive中创建外部表

hive中创建外部表


删除外部表并不会删除掉这份数据,不过描述表的元数据信息会被删除掉

1. 在hive所在的目录下创建所有文件所在的管理目录

[admin@hadoop-senior02 hive-0.13.1-cdh5.3.6]$ mkdir input
[admin@hadoop-senior02 hive-0.13.1-cdh5.3.6]$ cd input

2.编辑文件

[admin@hadoop-senior02 input]$ vim dept.txt

#添加以下内容
10      ACCOUNTING      NEW YORK
20      RESEARCH        DALLAS
30      SALES           CHICAGO
40      OPERATIONS      BOSTON

[admin@hadoop-senior02 input]$ vim emp.txt

#添加以下内容
7369	SMITH	CLERK		7902	1980-12-17	800.00			20
7499	ALLEN	SALESMAN	7698	1981-2-20	1600.00	300.00	30
7521	WARD	SALESMAN	7698	1981-2-22	1250.00	500.00	30
7566	JONES	MANAGER		7839	1981-4-2	2975.00			20
7654	MARTIN	SALESMAN	7698	1981-9-28	1250.00	1400.00	30
7698	BLAKE	MANAGER		7839	1981-5-1	2850.00			30
7782	CLARK	MANAGER		7839	1981-6-9	2450.00			10
7788	SCOTT	ANALYST		7566	1987-4-19	3000.00			20
7839	KING	PRESIDENT	7777	1981-11-17	5000.00			10
7844	TURNER	SALESMAN	7698	1981-9-8	1500.00	0.00	30
7876	ADAMS	CLERK		7788	1987-5-23	1100.00			20
7900	JAMES	CLERK		7698	1981-12-3	950.00			30
7902	FORD	ANALYST		7566	1981-12-3	3000.00			20
7934	MILLER	CLERK		7782	1982-1-23	1300.00			10

3.创建表dept

create external table if not exists default.dept(
deptno int,
dname string,
loc int
)
row format delimited fields terminated by '\t';

4.创建表dept

create external table if not exists default.emp(
empno int,
ename string,
job string,
mgr int,
hiredate string, 
sal double, 
comm double,
deptno int)
row format delimited fields terminated by '\t';

5.向外部表中导入数据

hive (default)> load data local inpath ‘/opt/moudles/cdh/hive-0.13.1-cdh5.3.6/input/dep.txt’ into table dept;
hive (default)> load data local inpath ‘/opt/moudles/cdh/hive-0.13.1-cdh5.3.6/input/emp.txt’ into table emp;

6.查询表

hive (default)> select * from emp;
hive (default)> select * from dept;

7.查看表的类型

hive (default)> desc formatted emp;

#查看其中一个字段
Table Type:         	EXTERNAL_TABLE 

你可能感兴趣的:(hive)