Table alteration

Once a table is created, we can still modify its metadata, such as adding new columns and changing the column's data type. In HQL, we use the ALTER command to modify the table's metadata. However, alter table is not able to update the data accordingly. We should make sure the actual data conforms to the metadata definition manually, otherwise the query will return nothing in expectation.

The following are examples for altering tables in HQL:

  1. Rename a table with the ALTER statement. This is quite often used as data backup:
      > ALTER TABLE cte_employee RENAME TO cte_employee_backup;      No rows affected (0.237 seconds)
  1. Change the table properties with TBLPROPERTIES:
      > ALTER TABLE c_employee SET TBLPROPERTIES  ('comment'='New ...

Get Apache Hive Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.