Apache Hive ALTER TABLE Command and Examples

  • Post author:
  • Post last modified:December 25, 2019
  • Post category:BigData
  • Reading time:3 mins read

You can use the Apache Hive ALTER TABLE command to change the structure of an existing table. You can add, modify existing columns in Hive tables.

Apache Hive ALTER TABLE Command

Uses of Hive ALTER TABLE Command

Below are the most common uses of the ALTER TABLE command:

  • You can rename table and column of existing Hive tables.
  • You can add new column to the table.
  • Rename Hive table column.
  • Add or drop table partition.
  • Add Hadoop archive option to Hive table.

Related reading:

Hive ALTER TABLE Command Syntax

Below is syntax of commonly used ALTER TABLE commands:

https://gist.github.com/dee8ff0ad3a522a2c5d9d6f260a6075b

Hive ALTER TABLES Command Examples

Below are some of the examples of ALTER TABLE commands:

Rename Hive Table using ALTER TABLE Command

Sometimes you have to rename the table in the Hive. Hive alter command allows you to rename the Hive table. Here is an example for the same:

https://gist.github.com/821aeed7cb046594ce71a60a43f27da4

Add new column to Hive Table using ALTER TABLE Command

Here is the example to add new column to the existing Hive table.

https://gist.github.com/2b8ab5c83dfadc29e41755c74b2a5b86

Change Hive Table Column name and Type using ALTER command

You can change the column name and type of the existing Hive table using Hive alter command

https://gist.github.com/45e6f2383bcd26fc81fcc462c2aa1328

Add and Drop Partition using ALTER TABLE Command

You can add new partition or drop the existing partition using Hive alter command

https://gist.github.com/8870ff09b5e02ffad1133d5f10148430

Related readings:

Hope this helps 🙂