Hello Dirhen,
thanks for your reply.
At your process, I would move the "--reorg the table" after the ALTER TABLE .... DROP COLUMN, as this is a Pending DDL change.
Kind regards!
------------------------------
Soledad Martinez
Db2 z/OS System Programmer
Volkswagen Group Services
Salinas - Asturias
------------------------------
-------------------------------------------
Mensaje original:
Enviado: Fri July 04, 2025 05:38 AM
De: Dhirendra Chaudhary
Sujeto: ALTER TABLE ... ALTER COLUMN ... SET NOT NULL
Hi,
you could achieve this in a round about way.
consider your table xxx.DOCU_TABLE_TEST
-- add a new column
alter table xxx.DOCU_TABLE_TEST add column FILE_TOSTORE_NN not null with default ;
-- reorg the table
-- copy the not null values from existing column to new column (this may not be an issue for you as the table is empty)
update xxx.DOCU_TABLE_TEST
set FILE_TOSTORE_NN = FILE_TOSTORE
where FILE_TOSTORE is not null ;
-- alter table xxx.DOCU_TABLE_TEST alter column FILE_TOSTORE_NN DROP DEFAULT ;
-- alter table xxx.DOCU_TABLE_TEST drop column FILE_TOSTORE restrict ;
-- alter table xxx.DOCU_TABLE_TEST rename column FILE_TOSTORE_NN to FILE_TOSTORE ;
------------------------------
Dhiren Chaudhary
Natwest Group
Original Message:
Sent: Thu July 03, 2025 09:06 AM
From: Soledad Martinez
Subject: ALTER TABLE ... ALTER COLUMN ... SET NOT NULL
Hello Db2 people,
we had a request to change a column from NULL to NOT NULL, at the beginning I doubt it could be possible thanks to that the table was still empty, so no rows, no null value to deal with.
Anyway, after trying seems that it's not possible, althought the error message is not clear about the problem:
ALTER TABLE XXX.DOCU_TABLE_TEST
ALTER COLUMN FILE_TOSTORE SET NOT NULL;
-------------------------------
DSNT408I SQLCODE = -199, ERROR: ILLEGAL USE OF KEYWORD NOT. TOKEN WITH
DEFAULT DATA INLINE CACHE MAXVALUE MINVALUE NOCACHE WAS EXPECTED
Just in case we tried other things ... ALTER TABLE ... ALTER COLUMN ... WITH DEFAULT 'whatever", or ALTER TABLE ... ALTER COLUMN ... DROP DEFAULT ... but no success.
So when you go back to the deloper that requested this it's not easy to clarify where was the problem. I like to reply specifying where the problem is, but also adding some links to IBM site and/or some quote from IBM where it be specified.
But I was not able to find such a link, in fact, checking the IBM site I even thought there could be a way:

So this made me doubt if there was a way to do it, probably this is the reason why I am posting this (insecurity ... :-) )
Anybody has a link for confirming this assumption?
Thanks,
Sole
The most solid argument I found to confirm that is not possible to change a column from NULL to NOT NULL, was this update in 2021 from my admired late Robert Catterall: DB2 for z/OS: Answering Some Questions About Adding and Dropping Table Columns
Robertsdb2blog | remove preview |
| DB2 for z/OS: Answering Some Questions About Adding and Dropping Table Columns | From the very beginning, you've been able to add a column to an existing DB2 for z/OS table by way of the SQL statement ALTER TABLE with the... | View this on Robertsdb2blog > |
|
|
------------------------------
Soledad Martinez
Db2 z/OS System Programmer
Volkswagen Group Services
Salinas - Asturias
------------------------------