In this post, I describe how to create a Hive Table.
Create Table Statement
The syntax and example to create a Hive table is as follows:
Syntax
|
1 2 3 4 5 6 |
CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.] table_name [(col_name data_type [COMMENT col_comment], ...)] [COMMENT table_comment] [ROW FORMAT row_format] [STORED AS file_format] |
For example, suppose you want to create a Table student, with the following attributes:
- id, the student’s ID number, the type is int,
- name, the type is String,
- age, the type is int,
- score, the type is Float,
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
hive (user_db)> CREATE TABLE IF NOT EXISTS students_db.student ( id int, > name String, > age int, score Float) > COMMENT 'Description of the table' > ROW FORMAT DELIMITED > FIELDS TERMINATED BY '\t' > LINES TERMINATED BY '\n' > STORED AS TEXTFILE; OK Time taken: 2.357 seconds hive (user_db)> describe students_db.student; OK id int name string age int score float Time taken: 0.04 seconds, Fetched: 4 row(s) |
Note:
- If you’re not currently working in the target database,











