In Hive, we can perform modifications in the existing table like changing the table name, column name, comments, and table properties. It provides SQL like commands to alter the table.
Rename a Table
If we want to change the name of an existing table, we can rename that table by using the following signature: -
- Let's see the existing tables present in the current database.

- Now, change the name of the table by using the following command: -

- Let's check whether the name has changed or not.

Here, we got the desired output.
Adding column
In Hive, we can add one or more columns in an existing table by using the following signature: -
- Let's see the schema of the table.

- Let's see the data of columns exists in the table.

- Now, add a new column to the table by using the following command: -

- Let's see the updated schema of the table.

- Let's see the updated data of the table.

As we didn't add any data to the new column, hive consider NULL as the value.
Change Column
In Hive, we can rename a column, change its type and position. Here, we are changing the name of the column by using the following signature: -
- Let's see the existing schema of the table.

- Now, change the name of the column by using the following command: -

- Let's check whether the column name has changed or not.

Delete or Replace Column
Hive allows us to delete one or more columns by replacing them with the new columns. Thus, we cannot drop the column directly.
- Let's see the existing schema of the table.

- Now, drop a column from the table.

- Let's check whether the column has dropped or not.

Here, we got the desired output.
No comments:
Post a Comment