nah... as you can see with my test the table is also 100% empty... makes no difference sadly...
Original Message:
Sent: Fri July 04, 2025 02:03 AM
From: James Campbell
Subject: ALTER TABLE ... ALTER COLUMN ... SET NOT NULL
Fortunately for the OP the table is empty. Which makes me think that a simple DROP COLUMN followed by an ADD COLUMN might be sufficient. Unless there is a requirement to have the columns in a particular order.
------------------------------
James Campbell
Original Message:
Sent: Fri July 04, 2025 01:24 AM
From: Roy Boxwell
Subject: ALTER TABLE ... ALTER COLUMN ... SET NOT NULL
Hi!
You are correct you cannot do this... I never figured out exactly why this is so badly documented but you can do nearly everything else in the whole world apart from this one ALTER! As Robert said the best (only!) way forward is to ALTER add a column NOT NULL, Update the column from the original changiikng and and all NULL vaules to a new value you choose, then ALTER DROP the column, REORG, ALTER rename the new column bnack to the old column, REORG... Phew! I would hope you could stack the last two ALTERs but you cannot...
DROP TABLE ROYTEST ;
COMMIT ;
CREATE TABLE ROYTEST (COL1 CHAR(1));
COMMIT ;
ALTER TABLE ROYTEST
ADD COLUMN COL2 CHAR(1) WITH DEFAULT NOT NULL ;
COMMIT ;
ALTER TABLE ROYTEST
DROP COLUMN COL1 RESTRICT
;
ALTER TABLE ROYTEST
RENAME COLUMN COL2 TO COL1
;
COMMIT;
You get a pending REORG at DROP COLUMN which must be done before you can do the RENAME...
Sounds like an AHA Idea !
------------------------------
Roy Boxwell
Senior Software Architect
Software Engineering GmbH
Duesseldorf
+4921196149675
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
------------------------------