IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to change not null column to nullable column


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
nightbuzzz

New User


Joined: 04 May 2007
Posts: 21
Location: kuala lumpur

PostPosted: Tue Nov 18, 2008 9:53 am
Reply with quote

I have a column in a table which is not null right now.

I want to change the attribute of that column to NULL.

How can it be done?

Can i use ALTER table command to achieve this?
Back to top
View user's profile Send private message
Prasanthhere

Active User


Joined: 03 Aug 2005
Posts: 306

PostPosted: Tue Nov 18, 2008 10:44 am
Reply with quote

Alter command doesn't work for your criteria .

You have to export the data drop the table and recreate the the table with the required column to be null
Back to top
View user's profile Send private message
Prasanthhere

Active User


Joined: 03 Aug 2005
Posts: 306

PostPosted: Tue Nov 18, 2008 10:51 am
Reply with quote

I f you are using DB2 V9 it can be done through ALTER I guess

Please go through this link

publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/r0000888.htm
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Tue Nov 18, 2008 12:07 pm
Reply with quote

You can add a constraint for this.

ALTER TABLE <TABLENAME> ADD CONSTRAINT NULL_FIELD CHECK (<FIELD> IS NOT
NULL)
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Nov 18, 2008 10:38 pm
Reply with quote

Hello,

I believe you have posted the way to create a new constraint.

What TS asked for is how to remove this constraint using ALTER (if i understand correctly).

Prasanth has posted the 2 answers - 1 if db2 is prior v9 and 1 if v9 has been installed.
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Wed Nov 19, 2008 11:19 am
Reply with quote

Dick,
You are right. But I am asking him to add a constraint to check for NULLs, which will avoid dropping and creating the table once again.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 19, 2008 8:30 pm
Reply with quote

Hello Srihari,

Quote:
But I am asking him to add a constraint to check for NULLs
I believe that is what is already defined and the requirement is to remove it.

I may be mistaken and we haven't heard from TS since the question was asked. . .
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Nov 20, 2008 11:12 am
Reply with quote

Hi,
Please ignore my post. Actually, TS wanted to make a NOT NULL column to NULLABLE. My solution is to make a NULLABLE column to NOT NULL.
Back to top
View user's profile Send private message
ashok_uddaraju

New User


Joined: 21 Feb 2007
Posts: 72
Location: US

PostPosted: Thu Nov 20, 2008 1:46 pm
Reply with quote

Yes alter can be used for this change
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Nov 21, 2008 12:40 am
Reply with quote

Hello,

Quote:
Yes alter can be used for this change
But only if the system is currently running v9. . . .?

Many (maybe most) systems are not yet running v9. . .
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Nov 21, 2008 12:45 am
Reply with quote

and anyway regardless of the db2 level,
altering on the fly a DB2 table might be acceptable in test..

NEVER IN PRODUCTION
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts 3270 personal communications. Can't c... TSO/ISPF 2
Search our Forums:

Back to Top