DDL(Data Definition Language) 用于数据库、表、视图等对象的创建与管理
DML(Data Manipulation Language) 用于数据加载、插入、更新、删除等操作
CREATE DATABASE [IF NOT EXISTS] database_name [COMMENT database_comment] [LOCATION hdfs_path] [WITH DBPROPERTIES (property_name=property_value, ...)] 示例: create database db_hive; #创建基础数据库db_hive create database if not exists db_hive;#创建数据库进行校验 create database db_hive2 comment "store resource info"; #创建数据库db_hive1并添加描述 create database db_hive2 location "/db_hive2.db";
#创建一个数据库,指定数据库在HDFS上存放的位置 DQL(Data Select Language) 用于数据查询 UDF(User-Defined Functions ) 内置函数(Built-in Functions) UDAF(Built-in Aggregate Functions ) UDTF(Built-in Table-Generating Functions) 用户自定义函数,用于辅助数据查询
查看Hive中所有数据库 SHOW DATABASES [LIKE 'identifier_with_wildcards']; 查看数据库信息 DESCRIBE DATABASE [EXTENDED]database_name 示例: show databases; #查看/显示所有数据库 show databases like "db*"; #过滤显示查询的数据库 desc database db_hive; #显示数据库信息 desc database extended db_hive; #显示数据库详细信息,extended
创表
create table stu(id int) create external table if not exists stu1(id int) create table if not exists stu2(id int, name string) create table if not exists student( id int, name string) row format delimited fields terminated by '\t'; create table if not exists student2(id int, name string) row format delimited fields terminated by '\t' location '/user/hive/warehouse/student2';
创建分区表语法 CREATE TABLE table_name (column1 data_type, column2 data_type….) PARTITIONED BY (partition1 data_type, partition2 data_type,….); 示例: create table dept_partition(deptno int, dname string, loc string) partitioned by (month string) row format delimited fields terminated by '\t';