hive-sql DDL常用语句

本文介绍了如何使用Hive创建表、临时视图,重命名表,进行数据操作如删列、清空和增删字段,以及管理分区、数据导入导出、创建视图等关键步骤。涵盖了从基础到高级的Hive SQL实践技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

建表:

create table if not exists xx;

创建临时视图:

create or replace temporary view table_name as

hive表重命名(无法修改成已建过的表):

alter table table_name rename to new_table_name;

删表:

drop table if exists xx;

删除一列:

alter table xx drop 列名;

清空表:

truncate table xx

添加表字段:

alter table  xx  add columns (member string comment '会员');

修改表字段顺序:

alter table xx change   字段名(需要修改的字段) 字段名 需要修改的字段)字段类型 after 字段名(具体在哪个字段之后)

alter table xx   A  A string after B; 

修改字段备注:

alter table xx change  column id id string comment 'ccid前三位';

删除分区:

alter table xx drop  partition (time='xx',date='xx',channel=' xx');

导入数据:

load data local inpath '/xx/xx.csv' overwrite into table xx;

插入数据:

insert overwrite xx partition (time,date,channel)

insert into xx partition (time,date,channel)

创建视图:

create or replace temporary view 视图名 as select ...

create or replace temporary view 视图名(

字段名 字段类型,

AA  string...)

USING org.apache.spark.sql.execution.datasources.csv.CSVFileFormat

OPTIONS(

PATH 'XX/XX',

header 'true',

delimiter '\001',

quote '"'

);

持续更新中。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值