Monday 4 July 2022

Hive: rename a table

Syntax

ALTER TABLE currentName RENAME TO newName;

 

Example

ALTER TABLE employee RENAME TO emp;

 

Login to hive shell by executing the command ‘hive’.

[cloudera@quickstart conf]$ hive

Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
WARNING: Hive CLI is deprecated and migration to Beeline is recommended.
hive> ;
hive> SHOW tables;
OK
employee
Time taken: 0.411 seconds, Fetched: 1 row(s)

 

As you see above snippet, I have employee table in default database. Let’s execute below statement to rename employee table to emp.

 

ALTER TABLE employee RENAME TO emp;
hive> ALTER TABLE employee RENAME TO emp;
OK
Time taken: 0.159 seconds
hive> ;
hive> ;
hive> SHOW tables;
OK
emp
Time taken: 0.032 seconds, Fetched: 1 row(s)

 


Previous                                                    Next                                                    Home

No comments:

Post a Comment