大数据之Hive:DDL数据定义(二)

1.创建表
01.创建普通表

create table if not exists student2(
id int, name string
)
row format delimited fields terminated by '\t'
stored as textfile
location '/user/hive/warehouse/student2';

02.根据查询结果创建表(查询的结果会添加到新创建的表中)

create table if not exists student3 as select id, name from student;

03.根据已经存在的表结构创建表

create table if not exists student4 like student;

2.查询表的类型

hive (default)> desc formatted student2;

3.外部表
删除该表并不会删除掉这份数据,不过描述表的元数据信息会被删除掉。
01.创建外部表

hive (default)> create external table stu_external(
id int, 
name string) 
row format delimited fields terminated by '\t' 
location '/student';

02.管理表与外部表的互相转换
02-1.修改内部表student2为外部表

alter table student2 set tblproperties('EXTERNAL'='TRUE');

02-2.修改外部表student2为内部表

alter table student2 set tblproperties('EXTERNAL'='FALSE');

注意:(‘EXTERNAL’=‘TRUE’)和(‘EXTERNAL’=‘FALSE’)为固定写法,区分大小写!

猜你喜欢

转载自blog.csdn.net/weixin_43597208/article/details/112539345