2

I have tried the following scripts to add a not null constraint to my column.

ALTER TABLE MYDB.RULES ALTER TYPEID SET NOT NULL;
ALTER TABLE MYDB.RULES ALTER COLUMN TYPEID SET NOT NULL;

I also get this error when I execute it:

 Reason code 10. [SQL State=57014, DB Errorcode=-952] 

Is it possible to do this in DB2 iSeries?

Loren
  • 1,260
  • 5
  • 16
  • 23

5 Answers5

4

First you have to identify and handle the NULL values of the target table ( update, delete, etc. )

SELECT COUNT(1) FROM MYDB.RULES WHERE TYPEID IS NULL;

Than you can create the constraint on the target table.

ALTER TABLE MYDB.RULES ALTER COLUMN TYPEID SET NOT NULL;
Zoli
  • 61
  • 4
1
ALTER TABLE MYDB.RULES ALTER TYPEID SET NOT NULL;

Is correct.

How are you issuing the statement?

The error code you report, SQL State= 57014 - Processing was canceled as requested.

Leads me to believe that however you're running the statement, you're not seeing the CPA32B2 - Change of file RULES may cause data to be lost. (C I) inquiry message; thus it's getting automatically answered with a C-Cancel.

Charles
  • 21,637
  • 1
  • 20
  • 44
  • Any solution to force an "I" answer using SQL ? This is a real pain in the foot with DB2/iSeries... – Chucky Mar 31 '21 at 14:13
  • 1
    Google `CPA32B2`, you can Add Reply List Entry (`ADDRPYLE`) and Change Job (`CHGJOB`) to use the system reply list. – Charles Mar 31 '21 at 15:07
0

try this, with type of column

ALTER TABLE yourlib/yourtable ALTER COLUMN yourcolumn SET DATA 
TYPE VARCHAR ( 100) NOT NULL                           
Esperento57
  • 16,521
  • 3
  • 39
  • 45
0

If you want a constraint you add a constraint. First you make sure all the rows in the table satisfy the constraint then add the constraint.

update mylib/myfile set myfield = ' ' where myfield is null;
ALTER TABLE mylib/myfile ADD CONSTRAINT myfieldisnull CHECK (myfield is not null );
danny117
  • 5,581
  • 1
  • 26
  • 35
0

May be you altered the table before and didn't run the Reorg command. Run this:

CALL SYSPROC.ADMIN_CMD('REORG TABLE MYDB.RULES');
anothernode
  • 5,100
  • 13
  • 43
  • 62