DB2 ALTER TABLE: Add Fields & Comments
In DB2 database, you can use the ALTER TABLE statement to add columns and comments.
For example, if a table named “employees” needs to add a new field called “salary” and provide a comment for this field, you can use the following SQL statement:
ALTER TABLE employees
ADD COLUMN salary DECIMAL(10, 2) DEFAULT 0,
ADD COLUMN comment VARCHAR(100);
COMMENT ON COLUMN employees.salary IS '员工工资';
COMMENT ON COLUMN employees.comment IS '备注';
In the above code, we used the ALTER TABLE statement to add two new fields “salary” and “comment” to the “employees” table, and used the COMMENT ON COLUMN statement to add comments to these two fields.
It’s important to note that the ALTER TABLE statement in DB2 may impact the performance of a table, especially when adding a new field to a large table. Therefore, it is recommended to backup data and create indexes before executing the ALTER TABLE statement to ensure data integrity and performance.