Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




HIVE ALTER TABLE Statement

This command is used to add new columns to the end of existing column.


Syntax:


ALTER TABLE <tablename> ADD COLUMNS (
column1 datatype [COMMENT tablecomment],
column2 datatype [COMMENT tablecomment],
...
columnN datatype [COMMENT tablecomment]);



Example:

ALTER TABLE Employee ADD COLUMNS (
designation string COMMENT 'Employee designation',
age int COMMENT 'Employee Age');

ALTER TABLE - Replace Column

This command is used to remove all the existing column and replace it with the new columns specified.



Syntax:


ALTER TABLE <tablename> REPLACE COLUMNS (
column1 datatype [COMMENT tablecomment],
column2 datatype [COMMENT tablecomment],
...
columnN datatype [COMMENT tablecomment]);


Example:

ALTER TABLE Employee REPLACE COLUMNS (
employee_id string COMMENT 'Employee id',
first_name string COMMENT 'Employee First name',

ALTER TABLE - Renaming Table

This command is used to rename the table name to a new one.


Syntax:

ALTER TABLE<tablename> RENAME TO <new_tablename>


Example:

ALTER TABLE Employee RENAME TO NewEmployee