11.1.3 Changing the column name of a base table
To change the column name of a base table, execute the ALTER TABLE definition SQL statement.
The HADB user who defined the base table can use the ALTER TABLE statement to change the column name.
The following shows a specification example of changing the column name of a base table.
- Specification example
-
The name of the EMAIL_ADDRESS column of the shop table (SHOPSLIST) is changed to EMAIL.
ALTER TABLE "SHOPSLIST" RENAME COLUMN FROM "EMAIL_ADDRESS" TO "EMAIL"
For details about the specification format and rules for the ALTER TABLE statement, see ALTER TABLE (alter table definition) in the manual HADB SQL Reference.
Note that changing the column name of a base table might result in the following adverse affects. Check whether there is any adverse effect.
-
When there are viewed tables that depend on the base table whose column name was changed
The viewed tables that depend on the base table whose column name was changed are invalidated. Such viewed tables are invalidated regardless of whether the old column name (that was used before the column name was changed) is explicitly specified when viewed tables are defined.
To check the viewed tables that are to be invalidated (dependent viewed tables), see 11.2.11 Checking dependent viewed tables. If there is a viewed table that is invalidated, after using the ALTER TABLE statement to change the column name, you need to release the invalid status of the viewed table.
For details about how to release a viewed table from invalid status, see (2) When viewed tables are invalidated by using an ALTER TABLE statement to change a column name in a table in 11.2.8 Releasing a viewed table from invalidation.
-
When the old column name is explicitly specified in an SQL statement
You need to modify the old column name specified in an SQL statement to the new column name.
-
When the column structure information file is specified for the -r option of the adbimport command
If the old column name is specified by the column structure information option for the column structure information file, you need to modify the column name to the new column name.
You cannot use the ALTER TABLE statement to rename a column of the base table in the following situations:
-
When the target base table is non-updatable
In this case, after releasing the non-updatable status of the base table, execute the ALTER TABLE statement to change the column name. For details about how to release a base table from non-updatable status, see (1) Releasing a base table from non-updatable status in 15.8.1 Steps to take when a base table becomes non-updatable.