View previous topic :: View next topic
|
Author |
Message |
nightbuzzz
New User
Joined: 04 May 2007 Posts: 21 Location: kuala lumpur
|
|
|
|
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 |
|
|
Prasanthhere
Active User
Joined: 03 Aug 2005 Posts: 306
|
|
|
|
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 |
|
|
Prasanthhere
Active User
Joined: 03 Aug 2005 Posts: 306
|
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
You can add a constraint for this.
ALTER TABLE <TABLENAME> ADD CONSTRAINT NULL_FIELD CHECK (<FIELD> IS NOT
NULL) |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
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 |
|
|
ashok_uddaraju
New User
Joined: 21 Feb 2007 Posts: 72 Location: US
|
|
|
|
Yes alter can be used for this change |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
|