Friday, 10 March 2017

DB2 Alter Column

1. If a table is not empty, and we want to alter a column as NOT NULL.

ALTER TABLE my_table ALTER COLUMN name SET NOT NULL WITH DEFAULT 'None';


2. If we want the column to be nullable,

ALTER TABLE my_table DATA CAPTURE NONE;

ALTER TABLE my_table ALTER region DROP NOT NULL;


ALTER TABLE my_table DATA CAPTURE CHANGES; 

Since Drop column, and alter nullability is not allowed on any table with data capture on.
The data capture has to be changed.

After the ALTER TABLE statement, The access to the table is restricted.
You need to run the REORG command as follows:

CALL SYSPROC.ADMIN_CMD('REORG TABLE schema.table');

No comments:

Post a Comment