我是靠谱客的博主 任性万宝路,这篇文章主要介绍HiveQL:数据定义,现在分享给大家,希望可以做个参考。

一.数据库部分
1.创建数据库:

复制代码
1
2
3
4
create database dw; 或者create database if not exists dw; create database dw comment "this is a test database"; create database dw location 'my/prefered/location/'; create database dw with dbproperties ('creator'='linda','date'='2016-12-10')

备注:在所有数据库相关的命令中,都可以用SCHEMA这个关键字来代替关键字TABLE
2.显示创建的数据库:
show databases; show databases like ‘h.*’

3.描述数据库:
describe database dw; describe database
extended dw;

4.如果想在使用数据库的过程中显示使用的是哪个数据库,可以进行如下设置:
set hive.cli.print.current.db=true;

5.删除数据库:drop database if exists dw;
默认情况下:如果数据库中有表,是不能删除数据库的,这时如果非要删除可以这样:
drop database if exists dw CASDADE;

6.修改数据库:
alter database dw set dbproperties(‘edit_name’=’linda1’)
二.数据表部分
1.创建表部分:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
create table if not exists dw.table_1( name string comment '1', salary float comment '2', subordinates array<string> comment '3', deductions map<string,float> comment '4', address struct<street:string,city:string,state:string,zip:int> comment '5') comment 'describe table table_1' tblproperties ('createor'='linda','created_at'='2016-12-10') location '/user/hive/warehouse/dw/table_1'; create table if not exists dw.table_2 like dw.table_1;

2.展示报表
show tables;
show tables in dw_2;(在dw中看dw_2中的报表)
show tables ‘abc.*’;
3.描述报表:
describe extended table dw.table
describe formatted table dw.table
4.描述字段:
describe dw.table.name;

最后

以上就是任性万宝路最近收集整理的关于HiveQL:数据定义的全部内容,更多相关HiveQL内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部