0

I created sample table from Jupyter Lab notebook via:

file_csv = 'data.csv'
df = pd.read_csv(file_csv)
df.insert(0, 'KEY_ID', df.index)

Then added table to DB2 on IBM cloud via:

%sql PERSIST df

Looking at that table in DB2 console it is created w/o primary key - so I tried to remedy it:

ALTER TABLE DF
    ALTER COLUMN KEY_ID
    SET NOT NULL; 

And set KEY_ID as primary key:

ALTER TABLE DF
    ADD PRIMARY KEY(KEY_ID);

But DB2 stubbornly refuses with following error:

InternalError: (ibm_db_dbi.InternalError) ibm_db_dbi::InternalError: Exception('Statement Execute Failed: [IBM][CLI Driver][DB2/LINUXX8664] SQL0668N Operation not allowed for reason code "7" on table "MYID9999.DF". SQLSTATE=57016\r SQLCODE=-668')
[SQL: ALTER TABLE DF
ADD PRIMARY KEY(KEY_ID);]
(Background on this error at: http://sqlalche.me/e/2j85)

1 Answer 1

1

OK - I actually solved it while typing the question - but I will post it anyway. You need to REORG the table (I guess after resetting 'KEY_ID' column props to NOT NULL) and it only worked from when run like this:

CALL SYSPROC.ADMIN_CMD ('REORG TABLE DF')

But after that ALTER command works like a charm.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.