[SQL] 建表、查看表信息

建表

(1) 创建表

#复制表结构+表数据
create table targer_table as select * from source_table; 

#创建相同的表结构,不会复制表数据。
create table targer_table as select * from source_table where 1=2;
create table tableA like tableB;

#插入数据
insert into tableA  select ...

(2)创建分区表

create table test_part (id int,name string,no int) 
partitioned by (dt string)              # dt为分区字段
row format delimited fields terminated by '\t'  ;  # 用\t作分隔符

查看表信息

hive> show create table t1;  #显示创建表的sql语句
hive> show partitions t1;    #查看分区表,限定分区字段,查表更快
OK
dt=2018-02-09
dt=2018-03-05
Time taken: 0.064 seconds, Fetched: 2 row(s)

hive> desc t1;     #显示表信息
OK
statis_date             string                                                                       
item_code               string                                                                                       
# Partition Information          
# col_name              data_type               comment                           
dt                      string                                      
Time taken: 1.665 seconds, Fetched: 12 row(s)

猜你喜欢

转载自blog.csdn.net/sinat_25873421/article/details/80328847