Hive创建表格格式如下:
create [external] table [if not exists] table_name
[(col_name data_type [comment col_comment],)]
[comment table_comment]
[partitioned by(col_name data_type [comment col_comment],)]
[clustered by (col_name,col_name,...) [sorted by (col_name [asc|desc],...)] into num_buckets BUCKETS]
[row format row_format]
[stored as file_format]
[location hdfs_path]
1、创建数据库
Create database sjl;
执行如下图所示:
2、创建内部表
create table if not exists st_pptn_r_internal_text
(stcd string,
tm string,
drp double,
intv string,
pdr string,
dyp double,
wth string)
stored as orc
tblproperties('transactional'='true')
执行如下图所示:
3、创建外部表
create external table if not exists st_pptn_r_external
(stcd string,
tm string,
drp double,
intv string,
pdr string,
dyp double,
wth string)
location "/sjl"
执行如下图所示:
4、创建内部分区表
create table if not exists st_pptn_r_internal_partition_text
( tm string,
drp double,
intv string,
pdr string,
dyp double,
wth string)
partitioned by(stcd string)
执行如下图所示:
注意:由于stcd作为分区依据,所以stcd不要出现在字段中,否则报错如下:
5、创建外部分区表
create external table if not exists st_pptn_r_external_partition
( tm string,
drp double,
intv string,
pdr string,
dyp double,
wth string)
partitioned by(stcd string)
location "/sjl1"
执行如下图所示: