Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making nullable columns nullable

Status
Not open for further replies.

luvcal

Programmer
Aug 10, 2001
54
US
Is there any way to make a column that is initially declared nullable to not nullable?? The scenario is this:
I am migrating a table and want to insert default values only during migration. Once the migration is complete, I don't want to insert default values. At first, I did this:
db2 alter table test add col1 not null with default 0;
I can't have col1 generate a default value when running the application and I don't think there is any way to remove the default generation after the fact (is there??).

Next I tried this:
db2 alter table test add col1;
db2 update test set col1 = 0;
I need to now set col1 to NOT NULL...HOW DO I DO THAT?? Is it possible? Thanks for all help.
 
Seems to me the simplest solution is to do your migration, export the data, drop and recreate the table with your new attributes, and import or load the data back in...
 
I agree, but the keep-it-simple-stupid rule must apply here (for varying reasons), so I was hoping for column altering statements instead of a full blown migration scenario
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top