HiveQL:数据定义

来源:互联网 发布:淘宝新店引流量 编辑:程序博客网 时间:2024/05/17 15:38

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

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.创建表部分:

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;

0 0
原创粉丝点击