Hadoop HIVE 数据库表操作

kamisamak 发布于 2019-11-21 1898 次阅读


创建数据库表语法

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]
详细说明 展开 / 收起

 

[dangerbox title="例"]

创建表并指定字段之间的分隔符

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

根据查询结果创建表

create table stu3 as select * from stu2;

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

create table stu4 like stu2;

查询表的类型

desc formatted stu2;
创建外部表 并用'\t'分割
create external table techer (t_id string,t_name string) row format delimited fields terminated by '\t';
从本地文件系统向表中加载数据
load data local inpath '/export/servers/hivedatas/student.csv' into table student;

加载数据并覆盖已有数据

load data local inpath '/export/servers/hivedatas/student.csv' overwrite into table student;
分区表 展开 / 收起
进行表的修复 展开 / 收起
分桶表 展开 / 收起
修改表 展开 / 收起
hive表中加载数据 展开 / 收起
hive表中的数据导出 展开 / 收起

[/dangerbox]