[Hive_7] Hive 中的 DDL 操作

时间:2023-03-10 03:47:17
[Hive_7] Hive 中的 DDL 操作

0. 说明

  DDL(Data Definition Languages)语句:数据定义语言
  这些语句定义了不同的数据段、数据库、表、列、索引等数据库对象的定义。
  常用的语句关键字主要包括 create、drop、alter 等。


1. create

  1.1 仅复制表结构

  创建user_par2,与user_par表结构一致,但是没有数据

  create table user_par2 like user_par; 

  1.2 复制表数据

  创建user_par2,与user_par完全一致,包括数据,但是分区会被变为字段

  create table user_par3 as select * from user_par; 

2. drop

  2.1 删除分区

    alter table  user_par2 drop partition(province='sichaun');

3. alter

# 1.修改表名
alter table wc rename to wc3; # 2.添加列
alter table customers add columns(wife string); # 3.删除列,不能用
alter table customers drop column wife; # 4.替换所有列,修改字段名
alter table customers replace columns(id int, name string, age int); # 5.将id列改名为no,类型为string
alter table customers change column id no string;