Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a column nullable in DB2 when Data Capture is enabled

Tags:

I'm using 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);
like image 535
lukewm Avatar asked Aug 02 '11 13:08

lukewm


People also ask

How do you change a column from not null to NULL in Db2?

If you have a column that does not allow the null value and you want to change it to now allow the null value, use the DROP NOT NULL clause. If you have a column that allows the null value and you want to prevent the use of null values, use the SET NOT NULL clause.

How do you change a column is nullable?

ALTER TABLE table_name ALTER COLUMN column_name DATA_TYPE [(COLUMN_SIZE)] NULL; In this syntax: First, specify the name of the table from which you want to change the column. Second, specify the column name with size which you want to change to allow NULL and then write NULL statement .

What does it mean for a column to be nullable?

It means, if a column nullable type is defined as 0, it means it cannot be NULL, every time it will have some value.


1 Answers

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;
like image 153
lukewm Avatar answered Oct 20 '22 23:10

lukewm