How can multiple fields be added in DB2?

In DB2, multiple fields can be added using the ALTER TABLE statement.

Here is the grammar.

ALTER TABLE table_name
ADD COLUMN column_name1 data_type,
ADD COLUMN column_name2 data_type,
...

In this case, table_name represents the name of the table where the fields are to be added, column_name1, column_name2, and so on, represent the names of the fields to be added, and data_type represents the data type of the fields.

For example, to add two fields (address and phone) to a table named employees, you can use the following statement:

ALTER TABLE employees
ADD COLUMN address VARCHAR(100),
ADD COLUMN phone VARCHAR(20);

Two new fields, named address and phone, will be added to the employees table with data types VARCHAR(100) and VARCHAR(20) respectively.

bannerAds