How to copy all hive table from one Database to other Database

Aman picture Aman · Oct 29, 2014 · Viewed 60.3k times · Source

I have default db in hive table which contains 80 tables .
I have created one more database and I want to copy all the tables from default DB to new Databases.

Is there any way I can copy from One DB to Other DB, without creating individual table.

Please let me know if any solution.. Thanks in advance

Answer

Venkat Ankam picture Venkat Ankam · Oct 29, 2014

I can think of couple of options.

  1. Use CTAS.

    CREATE TABLE NEWDB.NEW_TABLE1 AS select * from OLDDB.OLD_TABLE1;
    CREATE TABLE NEWDB.NEW_TABLE2 AS select * from OLDDB.OLD_TABLE2;
    ...
    
  2. Use IMPORT feature of Hive https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ImportExport

Hope this helps.