If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Set Column type not null-- Giving error.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-05-11, 15:16
Rajesh1203 Rajesh1203 is offline
Registered User
 
Join Date: Aug 2010
Posts: 38
Set Column type not null-- Giving error.

Hello,
I have a table with 1000 records,I just added a varchar column and refreshed data in that column.Now I am trying add a not null constraint to that column so that I can make it part of the unique key but it is throwing an error:

Here is the syntax for the column:
ALTER TABLE TABLENAME ALTER COLUMN COLUMNNAME SET NOT NULL;
----------------------
Error:
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "NOT" was found following "R COLUMN SRC_TYP
SET". Expected tokens may include: "DEFAULT". SQLSTATE=42601

SQL0104N An unexpected token "NOT" was found following "R COLUMN SRC_TYP SET". Expected tokens may include: "DEFAULT ".

Explanation:

A syntax error in the SQL statement or the input command string for the
SYSPROC.ADMIN_CMD procedure was detected at the specified token
following the text "<text>". The "<text>" field indicates the 20
characters of the SQL statement or the input command string for the
SYSPROC.ADMIN_CMD procedure that preceded the token that is not valid.

As an aid, a partial list of valid tokens is provided in the SQLERRM
field of the SQLCA as "<token-list>". This list assumes the statement is
correct to that point.

The statement cannot be processed.

User response:

Examine and correct the statement in the area of the specified token.

sqlcode: -104

sqlstate: 42601

-------------------------------------------

Can someone tell me where the issue is?

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 07-05-11, 15:48
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The syntax looks OK to me. What DB2 version and OS are you using?

Andy
Reply With Quote
  #3 (permalink)  
Old 07-05-11, 15:56
Rajesh1203 Rajesh1203 is offline
Registered User
 
Join Date: Aug 2010
Posts: 38
Db2 8.2 on windows.
Reply With Quote
  #4 (permalink)  
Old 07-05-11, 15:59
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
That explains it. You cannot set NOT NULL in v8.2.

DB2 Universal Database


Andy
Reply With Quote
  #5 (permalink)  
Old 07-05-11, 16:06
Rajesh1203 Rajesh1203 is offline
Registered User
 
Join Date: Aug 2010
Posts: 38
ok ...but my actual requirement is to add this new column that I added today to an existing Unique constraint.
For that purpose, I have dropped the existing Unique constraint and tried to recreate with this new column as part of it..But I am getting error saying that I cannot add a column to a unique if it is not defined not null.
Reply With Quote
  #6 (permalink)  
Old 07-05-11, 16:18
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You will have to add the column with NOT NULL WITH DEFAULT ''. Then fill in the data the way you want it, then ALTER TABLE ALTER COLUMN DROP DEFAULT.

Andy
Reply With Quote
  #7 (permalink)  
Old 07-05-11, 16:19
Rajesh1203 Rajesh1203 is offline
Registered User
 
Join Date: Aug 2010
Posts: 38
Anyways ...This is what I did...REnamed the table,Then dropped all foriegn Key Constraints,Created new table with that name and reloaded data back into the table
and put back the FK constraints. Tough though,any other solution.
Reply With Quote
  #8 (permalink)  
Old 07-05-11, 16:20
Rajesh1203 Rajesh1203 is offline
Registered User
 
Join Date: Aug 2010
Posts: 38
Quote:
Originally Posted by ARWinner View Post
You will have to add the column with NOT NULL WITH DEFAULT ''. Then fill in the data the way you want it, then ALTER TABLE ALTER COLUMN DROP DEFAULT.

Andy
Yeah by mistake I have added the column without the Default value.Anyways thanks for all your help.
Reply With Quote
  #9 (permalink)  
Old 07-06-11, 05:17
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by Rajesh1203 View Post
Anyways ...This is what I did...REnamed the table,Then dropped all foriegn Key Constraints,Created new table with that name and reloaded data back into the table
and put back the FK constraints. Tough though,any other solution.
You could/should consider moving to a newer version. V8 is out of support for several years now.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On