创建库
CREATE DATABASE DATABASENAME;
创建表
CREATE [EXTERNAL] TABLE TABLENAME (FIELD FIELDTYPE,......)
[PARITITIONED BY (FIELD TYPE)]
[ROW FORMAT ..] //DELIMITED FIELDS TERMINATED BY 'REG'
[FIELD STRUCT TERMINATED ......] //列信息
[LOCATION '']
[COMMENT ''];
删除表
DROP TABLE TABLENAME; //外部表不会被删除数据
表分区
//添加
ALTER TABLE TABLENAME ADD IF NOT EXISTS
PARTITION (FIELD = VALUE,......) [LOCATION '']
...;
//删除
ALTER TABLE TABLENAME DROP IF EXISTS PARTITION(FIELD = VALUE ,......);
其他操作
//修改列信息
ALTER TABLE TABLENAME
CHANGE COLUMN FIELD NEW_FIELD NEW_TYPE
[COMMIT '']
AFTER OTHER_FIELD;
// ADD COLUMN 增加
// REPLACE COLUMN 删除并替换
//修改表信息
ALTER TABLE TABLENAME SET TBLPROPERTIES(KEY = VALUE,...);
//装载数据
LOAD DATA LOCAL INPATH 'path'
OVERWRITE INTO TABLE TABLENAME
[PARTITION ()]
//分区目录不存在,会自动创建,没有分区,则可以忽略