Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to change not null column to nullable column

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: How to change not null column to nullable column
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    Post subject: Reply to: How to change not null column to nullable column
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    Post subject:
Reply with quote

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

Please go through this link

http://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    Post subject:
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

Site Director


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

PostPosted: Tue Nov 18, 2008 10:38 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Nov 19, 2008 8:30 pm    Post subject:
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    Post subject:
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: 74
Location: US

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

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

Site Director


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

PostPosted: Fri Nov 21, 2008 12:40 am    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10457
Location: italy

PostPosted: Fri Nov 21, 2008 12:45 am    Post subject: Reply to: How to change not null column to nullable column
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Repeat Sequence Number Until change i... rahulabvp DFSORT/ICETOOL 6 Thu Mar 29, 2018 12:51 pm
No new posts Query to compare 2 values of 1 column... Poha Eater DB2 13 Fri Mar 09, 2018 10:45 am
No new posts How to change the logon screen info o... sakthikumarT TSO/ISPF 4 Fri Dec 29, 2017 6:44 pm
No new posts Change NULL indicator in UNLOAD utility Khadhar Basha DB2 2 Fri Dec 15, 2017 3:01 pm
No new posts Extract record for change in combinat... Trinadh DFSORT/ICETOOL 6 Thu Nov 23, 2017 3:32 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us