Make a column nullable in DB2 when Data Capture is enabled
I'm usi开发者_如何转开发ng db2 version 9.7* and it seems impossible to make a NOT NULL column nullable in any straightforward way.
Unfortunately the solution of using a more developer friendly database is not available. Basically, in MySQL speak, I want to do something like this (where MY_COLUMN used to be VARCHAR(200) NOT NULL) :
ALTER TABLE MY_TABLE MODIFY COLUMN MY_COLUMN VARCHAR(200);
My final query ended up something like this:
ALTER TABLE MY_TABLE DATA CAPTURE NONE;
ALTER TABLE MY_TABLE ALTER MY_COLUMN DROP NOT NULL;
ALTER TABLE MY_TABLE DATA CAPTURE CHANGES;
the documentation says that the ALTER TABLE has the possibility to DROP NOT NULL
ALTER TABLE TABLE_NAME ALTER COLUMN COLUMN_NAME DROP NOT NULL;
works in DB2 9.7 and above. How ever you might want to perform a table reorg (in 9.7 db2 puts the table in reorg pending state, the same in 10.5 FP 5 too):
call sysproc.admin_cmd('reorg table TABLE_NAME');
精彩评论