Now we are in currently inside a database named madan-hv2-table. To list the tables under the madan-hv2-table.
0: jdbc:hive2://itmaddy.in:2181,madan-hv1> show tables;
+———–+–+
| tab_name |
+———–+–+
| mdy_emp |
+———–+–+
We are seeing one table named mdy_emp in the database madan-hv2-table. We let create a new database named with madan-hv2
0: jdbc:hive2://itmaddy.in:2181,madan-hv1> create database madan-hv2;
No rows affected (0.875 seconds)
Move table from madan-hv2-table database to madan-hv2 database
Hive offers a convenient alter table..rename command to move a Hive table from one database to another.
0: jdbc:hive2://itmaddy.in:2181,madan-hv1> alter table mdy_emp rename to madan-hv2.mdy_emp;
No rows affected (0.741 seconds)
We don’t see the mdy_emp table anymore when we now list the tables under madan-hv2-table.
0: jdbc:hive2://itmaddy.in:2181,madan-hv1> show tables;
+———–+–+
| tab_name |
+———–+–+
+———–+–+
No rows selected (0.487 seconds)
Let’s switch to madan-hv2 database and list the tables again. There you go, mdy_emp table is under madan-hv2 which is exactly what we wanted.
0: jdbc:hive2://itmaddy.in:2181,madan-hv1> use madan-hv2
0: jdbc:hive2://itmaddy.in:2181,madan-hv1> show tables;
+———–+–+
| tab_name |
+———–+–+
| mdy_emp |
+———–+–+