How to create an empty copy of a table in hive

gjin picture gjin · Jan 17, 2017 · Viewed 7k times · Source

I have a table with lots of columns. I don't want to write something like

CREATE TABLE IF NOT EXISTS 
table1( 
col1 int, 
col2 String,
etc....)

Is there a fast way to create a table with the same structure, but without any data?

Answer

leftjoin picture leftjoin · Jan 17, 2017

Try this:

CREATE TABLE some_db.T1 LIKE some_db.T2

See this manual: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTableLike