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:
- 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)
- Change the table properties with TBLPROPERTIES:
> ALTER TABLE c_employee SET TBLPROPERTIES ('comment'='New ...