DB2 alter: Add/delete/Reset Column
1. Add Fields
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: There are restrictions on changing the field type. For example, you can change the field to be larger than the previous type length. to change it to a smaller value or modify the decimal point length, you must drop the original column first, and then add 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, you cannot use the preceding statement to modify the column type. You must drop the column type first.
3. Remove Fields
Alter table [table_name] Drop column [column_name]
Note: After dropping a field, you may not be able to execute the Table query/insert operation. You Need To reorg the table.
4. Add default values for fields
Alter table [table_name] alter column [column_name] Set default [value]
5. Add fields with default values
Alter table [table_name] add column [column_name] [column_type] not null with default [value]
6. Set the default field time to the current time.
Alter table [table_name] alter column [column_name] Set default current date;