11.1.2 Adding a column to a base table
To add a column to 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 add a column.
Only a single column can be added, and it is added after the last column in the base table. Null values are stored in the added column.
The following shows a specification example of adding a column to a base table.
- Specification example
-
The column name EMAIL_ADDRESS is added to the shop table (SHOPSLIST). The data type of the column name EMAIL_ADDRESS is set to VARCHAR(100).
ALTER TABLE "SHOPSLIST" ADD COLUMN "EMAIL_ADDRESS" VARCHAR(100)
When you execute the ALTER TABLE statement, you can also specify NOT NULL or BRANCH for the column definition. For details about the specification format and rules for the ALTER TABLE statement, see ALTER TABLE (alter table definition) in Definition SQL in the manual HADB SQL Reference.
You cannot use the ALTER TABLE statement to add a column in the following situations:
-
The target base table becomes non-updatable.
-
The target base table is a FIX table, and the segments for storing rows have been assigned to the table.
-
For the target base table, for which segments for storing rows have been assigned, BRANCH ALL was specified when the CREATE TABLE statement was executed.
-
For the target base table, for which segments for storing rows have been assigned, NOT NULL is specified in the column definition of the ALTER TABLE statement.
If a column cannot be added because one of the preceding cases applies, see 15.8.2 When a column cannot be added to a base table.
For details about the status in which segments for storing rows are assigned, see 5.3.1 Notes on defining B-tree indexes (unfinished status of B-tree indexes).