Hive - DDL - Alter Table




Not able to play video? Try with youtube

Important Note - We recommend you to execute the given commands on Hive Console instead of Hue. The video is only for representational purposes.

Let's make changes in the table definition.

To rename a table x to x1, type ALTER TABLE x RENAME TO x1. Click on execute and refresh the list. Table x is renamed to x1.

To change the datatype of the column "a" in table x1 to Float, we can simply type ALTER TABLE x1 CHANGE a a FLOAT;. Click on execute and refresh the list. The datatype of column "a" is changed to float.

To add column "b" with float data type and column "c" with int data type, type ALTER TABLE x1 ADD COLUMNS (b FLOAT, c INT);. Click on execute and refresh the list. Now table x1 has two new columns "b" and "c".

INSTRUCTIONS

Steps:

  • Login to the web console
  • Launch Hive with typing in hive on the console. Run below commands in Hive.
  • Use your database by using the below command. ${env:USER} gets replaced by your username automatically:

    use ${env:USER};
    
  • To rename a table from x to x1

    ALTER TABLE x RENAME TO x1;
    
  • To change the data type of a column

    ALTER TABLE x1 CHANGE a a FLOAT;
    
  • To add columns to an existing table

    ALTER TABLE x1 ADD COLUMNS (b FLOAT, c INT);
    

Loading comments...