Search code examples
hivecreate-tablehiveddl

How to create an empty copy of a table in hive


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?


Solution

  • 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