Syntax
ALTER TABLE tableName CHANGE columnName newColumnName newColumnType
Example
ALTER TABLE employee CHANGE id emp_id BIGINT;
Above snippet rename the ‘id’ column of employee table to ‘emp_id’ and set the type to BIGINT.
Let’s experiment it with an example.
Step 1: Create user table.
CREATE TABLE employee (id INT, name STRING);
hive> CREATE TABLE employee (id INT, name STRING); OK Time taken: 0.133 seconds hive> ; hive> ; hive> DESC employee; OK id int name string Time taken: 0.062 seconds, Fetched: 2 row(s)
Step
2: Let’s
rename the column name ‘id’ to ‘emp_id’ and change the data type to BIGINT.
hive> ALTER TABLE employee CHANGE id emp_id BIGINT; OK Time taken: 0.116 seconds hive> ; hive> ; hive> DESC employee; OK emp_id bigint name string Time taken: 0.081 seconds, Fetched: 2 row(s)
No comments:
Post a Comment