Hive(6):创建表的四种方式

一、实现功能

在特定需求下,使用不同的创建表方式,创建需要的表。

二、创建方法

1、普通创建

create table student2(
num int,
name string
)
row format delimited fields terminated by'\t';

2.子查询方式(抽取源表的部分字段分析数据)

create table student_child as select * from student;

3、like方式

只是将表结构完全复制一份,不包含数据

create table student_like like student;

4、通过show create table student_child可以得到自动生成的建表语句

可以通过得到的信息在不同的集群中直接创建相应的表。

实例:

hive (hadoop)> show create table student_child;
OK
createtab_stmt
CREATE TABLE `student_child`(
`num` int, 
`name` string)
ROW FORMAT SERDE 
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 
STORED AS INPUTFORMAT 
'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://172.19.199.187:8020/user/hive/warehouse/hadoop.db/student_child'
TBLPROPERTIES (
'COLUMN_STATS_ACCURATE'='true', 
'numFiles'='1', 
'numRows'='18', 
'rawDataSize'='102', 
'totalSize'='120', 
'transient_lastDdlTime'='1541461438')
Time taken: 1.014 seconds, Fetched: 18 row(s)

 

你可能感兴趣的:(大数据开发,hive)