hive的基本语法

显示命令
•show tables;
•show databases;
•show partitions ;
•show functions
•describe extended table_name dot col_name
1.展示hive中所有的表:
SHOW TABLES;
2.正则匹配要查询的表
SHOW TABLES ‘sb_gbsj*’;
3.创建简单表:
CREATE TABLE sb_lbsjzb (sjid STRING,hh STRING,hm STRING,zdjh STRING);
4.创建表并创建索引字段ljdz:
CREATE TABLE sb_pwsjzb(sjid STRING,dwdm STRING,hh STRING,hm STRING ,jxfs INT) PARTITIONED BY (ljdz STRING);
5.复制一个空表:
CREATE TABLE temp_sb_gbsjzb LIKE sb_gbsjzb;
6.创建简单表,导入数据表的数据格式是<字段之间是tab键分割,行之间是断行>:
CREATE TABLE sb_gbxbdysj(sjid STRING,axdy STRING,bxdy STRING,cxdy STRING,sfyx INT)
row format delimited fields terminated by ‘\t’ lines terminated by ‘\n’;
7.表添加一列:
ALTER TABLE sb_gbsjzb ADD COLUMNS(cldh STRING);
8.表添加一列并增加注释:
ALTER TABLE sb_gbsjzb ADD COLUMNS(sbdz STRING COMMENT ‘sbdz’);
8.更改表名:
ALTER TABLE sb_lbsjzb RENAME TO temp_sb_lbsjzb;
9.删除表:
DROP TABLE temp_sb_gbsjzb;
10.描述表
describe sb_gbsjzb;
11.展示所有的函数
show functions;
12.创建分区表:
CREATE TABLE sb_gbfhsj(sjid STRING,sjsj STRING,axdy STRING,bxdy STRING)
COMMENT ‘this is gb data table’ PARTITIONED BY (rq STRING);
13.创建外部表:
CREATE EXTERNAL TABLE rz_gbrz (czsj STRING,czy STRING,cznr STRING COMMENT ‘connect about operation’)
COMMENT ‘this is rz table’ ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’;
14.创建Bucket表:
15.展示说有的数据库:
show databases;
16.删除分区:
ALTER TABLE table_name DROP partition_spec, partition_spec,…
17.修改列的名字、类型、位置、注释:
a.修改表中的字段名称:
alter table sb_gbsjzb change sbdz sbmc STRING;
b.修改表中的字段名称并添加注释变换字段在表中的位置:
alter table sb_gbsjzb change zdjh sbtm STRING comment ‘this is a new zdjh’ first;
c.则表示替换表中所有字段:
alter table sb_gbsjzb replace columns (sbxx STRING COMMENT ‘this is a sb info’);
18.改变表文件格式与组织:
•ALTER TABLE table_name SET FILEFORMAT file_format
•ALTER TABLE table_name CLUSTERED BY(userid) SORTED BY(viewTime) INTO num_buckets BUCKETS
19.创建数据库:
create database pw_data;
20.
21.创建视图:
create view view_sb_gbsjzb as select sjid,hh,hm from sb_gbsjzb;
22.描述视图:
desc view_sb_gbsjzb;
23.删除视图
drop VIEW view_name;
24.查看索引
•show index on salaries_external;
25.向数据表内加载文件

猜你喜欢

转载自blog.csdn.net/m0_37063257/article/details/78907667