CREATE [EXTERNAL] TABLE [IF NOT EXIST] table_name
[(col_name data_type [COMMENT COL_COMMENT],.....)]
[COMMENT table_comment]
[PARTITIONED BY (col_name data_type [COMMENT col_comment],....)]
[CLUSTERED BY (col_name,col_name,....)]
[SORTED BY (col_name [ASC|DESC],...)] INFO num_buckets BUCKETS]
[ROW FORMAT row_format]
[STORED AS file_format]
[LOCATION hdfs_path]
字段解释
-
CREATE TABLE创建一个指定名字的表,如果名字相同抛出异常,用户可以使用IF NOT EXIST来忽略异常
-
EXTERNAL关键字可以创建一个外部表,在建表的同时指定一个实际数据的路径(LOCATION),hive在删除表的时候,内部表的元数据和数据会被一起删除,而外部表只删除元数据,不删除数据
-
COMMENT是为表和列添加注释
-
PARTITIONED BY是分区表
-
CLUSTERED BY 是建分桶
-
SORTED BY不常用
-
ROW FORMAT定义行的格式
-
STORED AS 指定存储文件类型
-
LOCATION指定表在HDFS上的存储位置
-
LIKE允许复制现有的表结构但是不复制数据