Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 70
Location: bangalore

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: 10211
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 Fail to change physical VSAM filename... jacobdng CICS 6 Fri Jan 20, 2017 12:36 pm
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Syncsort - NULL in Integer field chec... nartcr SYNCSORT 4 Thu Oct 06, 2016 6:47 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us