基础建表语句:
CREATE [EXTERNAL] TABLE [IF NOT EXISTS] 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], ...)] INTO num_buckets BUCKETS]
[ROW FORMAT row_format]
[STORED AS file_format]
[LOCATION hdfs_path]
小demo:
create external table transaction1(id int,sex string,age int,date string,role string,region string) row format delimited fields terminated by ' ' stored as textfile location '/user/hdfs/source/hive_test' ;
1、创建表指定的路径
hadoop fs -mkdir /user/hdfs/source/hive_test
2、建表:包括是否外部表、表名、表字段、表属性。
a.指定分隔符:其中,FIELDS TERMINATED BY ‘\t’ 是指定字段分隔符也可用用其他符号如“,”,“|”等等,LINES TERMINATED BY '\n’是指定行分隔符(一般不写,默认是换