MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can I drop multiple columns in DB2

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
Lean
Beginner


Joined: 07 Aug 2012
Posts: 37
Topics: 11

PostPosted: Fri Aug 22, 2014 9:56 pm    Post subject: Can I drop multiple columns in DB2 Reply with quote

i just want to drop the last three fields from a table, as following comments from IBM knowledge center.
To add a column, issue the following statement:
ALTER TABLE SALES
ADD COLUMN SOLD_QTY
SMALLINT NOT NULL DEFAULT 0
To delete or drop a column, issue the following statement:
ALTER TABLE SALES
DROP COLUMN SOLD_QTY

Can i try to drop multiple columns with following scripts.

Code:

ALTER TABLE ABC
ADD COLUMN A SMALLINT NOT NULL DEFAULT 0
ADD COLUMN B SMALLINT NOT NULL DEFAULT 0
ADD COLUMN C SMALLINT NOT NULL DEFAULT 0;

ALTER TABLE ABC
DROP COLUMN C
DROP COLUMN B
DROP COLUMN A;
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Sat Aug 23, 2014 6:42 pm    Post subject: Reply with quote

Lean,

AFAIK you can only drop 1 column at a time with ALTER command on z/OS. However you can drop the entire table and recreate the table without the columns you don't need which is a way of dropping more than 1 column at a time.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lean
Beginner


Joined: 07 Aug 2012
Posts: 37
Topics: 11

PostPosted: Sat Aug 23, 2014 8:50 pm    Post subject: Reply with quote

Hi Kolusu,

I saw one other forum that they said make it, is there any other way without recreating the table, because there are some data in the table. the data should be reloaded after recreating the table.i just want to save time. you can refer to below link which is the google result.

http://stackoverflow.com/questions/875291/how-can-i-drop-multiple-columns-in-db2-on-aix
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Sun Aug 24, 2014 11:39 am    Post subject: Reply with quote

Lean,

The link is talking about AIX/WINDOWS. The DB2 version of z/OS is different from the open platform versions. On z/OS Drop column is supported in DB2 V11 which came out last September and AFAIK it only supports dropping a single column.

If you are concerned about reloading the table, then drop 1 column at a time and you wouldn't have to worry about unloading the data and then reloading it back again.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lean
Beginner


Joined: 07 Aug 2012
Posts: 37
Topics: 11

PostPosted: Sun Aug 24, 2014 8:34 pm    Post subject: Reply with quote

got it, thanks kolusu.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group