How can a new field be added to db2 with a default value?

To add a new column with a default value to a DB2 database table, you can use the following SQL statement:

ALTER TABLE table_name ADD COLUMN new_column_name data_type DEFAULT default_value;

table_name represents the name of the table where a new column is to be added, new_column_name represents the name of the new column to be added, data_type specifies the data type of the column, and default_value represents the value to be set as the default.

For example, to add a new field named “department” to a table called “employees” and give it a default value of ‘HR’, you can use the following SQL statement:

ALTER TABLE employees ADD COLUMN department VARCHAR(50) DEFAULT 'HR';
bannerAds