1. Add a field
ALTER TABLE [table_name] add [column_name] [Column_type]
2. Change the field type
ALTER TABLE [TABLE_NAME] ALTER COLUMN [COLUMN_NAME] Set data type [Column_type]
Note: Changes to the field type are limited, such as changing the field to be larger than the previous type, if you want to change the size or change the decimal length, you must first drop the original column and then add it again.
For example, I want to change the column of a varchar (10) to varchar (6) or change the column of a decimal (16, 2) to Decimal (16, 4), and so on, all of which cannot be modified using the above statement, but also to a different type. You also need to drop the column first.
3. Remove the field
ALTER TABLE [TABLE_NAME] drop column [column_name]
Note: After dropping the field, it may cause the table query/insert operation to not execute, and the table needs to be reorg.
4. Add a default value for a field
ALTER TABLE [TABLE_NAME] ALTER COLUMN [COLUMN_NAME] SET default [value]
5. Add a field with default values
ALTER TABLE [TABLE_NAME] Add column [column_name] [column_type] NOT NULL with default [value]
6. Set the default time for the field to the current time
ALTER TABLE [TABLE_NAME] ALTER COLUMN [COLUMN_NAME] set default current date;
DB2 Database Basic Add Delete table field summary