apache hive - Hive Alter Table - hive tutorial - hadoop hive - hadoop hive - hiveql
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
How to alter a table in Hive?
Alter Table Statement
- SQL ALTER TABLE statement is used to rename a table
- The SQL ALTER TABLE statement is used to add, modify, or drop/delete columns in a table
- It is used to alter a table in Hive.
Syntax
- The statement takes any of the following syntaxes based on what attributes we wish to modify in a table.
Rename To… Statement
- The following query renames the table from employee to emp
Sample Code:
apache hive - learn hive - hive tutorial - hive alter table - hive example
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
JDBC Program
- The JDBC program to rename a table is as follows.
- The following commands given are used to compile and execute this program.
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Sample Code:
Output:
- The following table contains the fields of employee table and it shows the fields to be changed (in bold).
Field Name | Convert from Data Type | Change Field Name | Convert to Data Type |
---|---|---|---|
eid | int | eid | int |
name | String | ename | String |
salary | Float | salary | Double |
designation | String | designation | String |
- The following queries rename the column name and column data type using the above data:
JDBC Program
- Given below is the JDBC program to change a column.
- The following commands given are used to compile and execute this program.
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Code
Output:
Add Columns Statement
- The following query adds a column named dept to the employee table.
JDBC Program
- The JDBC program to add a column to a table is given below.
- The following commands are done to compile and execute this program.
Sample Code:
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Output:
- The following query deletes all the columns from the employee table and replaces it with emp and name columns:
Syntax:
JDBC Program
- Given below is the JDBC program to replace eid column with empid and ename column with name.
- The following commands given are used to compile and execute this program.