Search This Blog

Creating a new Hive table with same schema of anothe Hive table.

In this article we will learn how to create a table with same schema of another table.

We use like operator in Apache Hive to copy schema from another table.

Syntax is : create table [new-table-name] like [old-table-name];

Practise below steps to understand better.

1) Create a new table called employee in Hive using this article.

2) Check the schema of Hive tables employee using describe command.

describe employee;

3) Create a new table called employee_india with same column names and data types of employee table.

create table employee_india like employee;

4) Now check column names and their data types of table employee_india.

describe employee_india;

We can copy schema not only from existing table, but also from existing existing view. Systax is also same , we just have to replace old-tablename with view name.