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 > DROP Column Or Add a NOT NULL Constraint

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-10-06, 12:24
sbaru sbaru is offline
Registered User
 
Join Date: Jun 2003
Location: Ohio
Posts: 148
DROP Column Or Add a NOT NULL Constraint

Hi- I am new to the DB2 world. I wanted to add a not null column with a default to an existing table with data. Not realizing I could do that, I added the column as a Nullable column, updated the existing data. Now I need to add a NOT NULL constraint. Could I do that? If not, I would like to DROP the column. I tried the syntax
ALTER TABLE <tableName> DROP COLUMN <columnName>.

I get an error "SQL0104N An unexpected token "C_CNTR_VST_FR_SFE" was found following "". Expected tokens may include: "KEY "."

Any help is greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 04-10-06, 12:31
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Three options :

a) Export data, drop table, create table with the proper defn and load data

b) Use Control Centre to ALTER - Assuming you are 8.2+ (always mention your version and OS) , all steps in option a is done behing the scenes.

c) Add a NOT NULL CHECK Constraint on the column
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 04-10-06, 12:52
sbaru sbaru is offline
Registered User
 
Join Date: Jun 2003
Location: Ohio
Posts: 148
Thanks Satya. Did not realize I could not DROP a column. That is kinda interesting. I will try the option A.

Thanks for your time again.
Reply With Quote
  #4 (permalink)  
Old 04-10-06, 20:14
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by sbaru
Thanks Satya. Did not realize I could not DROP a column.
There is no "alter table drop column" in the SQL Reference manual.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
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