03-hive的数据库操作

hive的数据库操作

规则语法

大小写规则:

1. hive的数据库名、表名都不区分大小写
2. 建议关键字大写

命名规则:

1.名字不能使用数字开头
2.不能使用关键字
3.尽量不使用特殊符号
库操作语法
hive> create database test;
hive> create database  if not exist test;
hive> create database  if not exist test comment "this is a comment";

hive> select * from DBS; # 查看数据库
hive> select * from TBLS; # 查看表

hive> show database;
hive> use mydb;  #切换数据库
hive> desc database test1; # 查看数据库信息

hive> drop database test1  #删除数据库 只能删除空库
hive> drop database test1 cascade; # 强制删除
表的基本操作
hive> create table t_user(id int,name string);
hive> select current_database(); #查看当前使用的数据库是哪个

hive> create table mydb.t_user(id int,name string); #指定mydb数据库
hive> show tables in mydb; #查看另外一个数据库中的表

hive> create table if not exists emp(
eno int,
uname string,
job string,
mgr int,
hiredate int,
salary int,
comm int,
deptno int
)
row format delimited
fields terminated by ','
lines terminated by '\n'
stored as textfile;

hive> desc t1  # 查看表结构
hive> desc extended t1; #查看表结构 更详细

hive> alter table t1 rename to t2 #改表名 
hive> alter table t2 change column uname sname string; #改列名

hive> alter table t2 change column english english int after chinese; # 修改列的位置 
hive> alter table t2 change column english english int first; # 修改列的位置 


hive> alter table t2 add column (sex int,...); # 增加字段

hive> alter table t2 replace columns(
id int,
name int,
size int,
pic string
); #删除字段
# 注意:实际上是保留小括号内的字段


hive> drop table t2; #删除表
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值