hive03 .hive建表

1.建表语法

建表
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]   row format delimited fields terminated by “分隔符”
[stored AS file_format]
[location hdfs_path]

例子:

1,zs,12.f
2,ls,14,m
3,ww,16,f




create external table tb_user3 (id String ,
name String,
age int,
gender String
)
row format  delimited fields terminated by ',' 
location 'hdfs://linux01:8020/data/log/' ;


2.内部表和外部表

 1) external  外部表 
 2) 默认的    内部表  管理表  managertable

问?  什么是内部表 什么是外部表 ?  什么时候使用内部表  什么时候使用外部表
1 公共/原始数据  使用外部表
2 业务有关的业务报表使用管理表(内部表)

内部表和外部表的区别:

create table tb_log2(
id int ,
name string 
)
row format delimited fields terminated by "," 
location  '/data/log/' ; -- 管理表 ,路径默认本地为hdfs://linux01:8020

drop  table tb_log2 ;  -- 内部表:指定的路径下的数据会被删除
select * from tb_log ;  --没有数据  

create external  table tb_log2(  --外部表 
id int ,
name string 
)
row format delimited fields terminated by "," 
location  '/data/log/' ;

drop  table tb_log2 ;  -- 外部表:指定的路径下的数据不会被删除
select * from tb_log ;  --有数据    没有收别的表影响

 

 

 

 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值