Syntax
ALTER TABLE name ADD COLUMNS (col_spec[, col_spec ...])
Example
ALTER TABLE employee ADD COLUMNS ( organization STRING COMMENT 'Organization name in the compay', age INT COMMENT 'employee age');
Above snippet add two columns to employee table.
a. organization
b. age
Let’s experiment it with an example.
Step 1: Create employee table by executing below command.
CREATE TABLE employee (id INT, name STRING);
hive> CREATE TABLE employee (id INT, name STRING); OK Time taken: 0.061 seconds hive> ; hive> ; hive> DESC employee; OK id int name string Time taken: 0.06 seconds, Fetched: 2 row(s)
Let’s add couple of columns to employee table.
ALTER TABLE employee ADD COLUMNS ( organization STRING COMMENT 'Organization name in the compay', age INT COMMENT 'employee age');
hive> ALTER TABLE employee ADD COLUMNS ( > organization STRING COMMENT 'Organization name in the compay', > age INT COMMENT 'employee age'); OK Time taken: 0.132 seconds hive> ; hive> ; hive> DESC employee; OK id int name string organization string Organization name in the compay age int employee age Time taken: 0.057 seconds, Fetched: 4 row(s)
No comments:
Post a Comment