6

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?

leftjoin
  • 36,950
  • 8
  • 57
  • 116
gjin
  • 860
  • 1
  • 14
  • 28

1 Answers1

12

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

leftjoin
  • 36,950
  • 8
  • 57
  • 116
  • 3
    Additionally, you can just show the command that created the table using `SHOW CREATE TABLE `
    – Andrea Jan 17 '17 at 13:01
  • additionally, this comand will also create same partition table like the sourse table. – Song Jul 17 '23 at 10:32