How to drop 2 columns from DB2 table?



IBM's flagship relational database management system

How to drop 2 columns from DB2 table?

Postby shankar_dh » Thu Oct 30, 2014 12:31 pm

Hi,

I believe we do not have DROP COLUMN facility in DB2.
I have 8 columns in my table.I need to drop 2 columns.
Do we need to create new table with only 6 columns and drop the old table? If so, how to take care of the data what we already have in the table?
Can anybody suggest me best approach to do so?
shankar_dh
 
Posts: 41
Joined: Fri Mar 22, 2013 1:00 pm
Has thanked: 1 time
Been thanked: 0 time

Re: How to drop 2 columns from DB2 table?

Postby NicC » Thu Oct 30, 2014 6:44 pm

It may depend on your level of DB2. I found this article when Googling:
http://ibmsystemsmag.com/Blogs/db2utor/Archive/drop-column-support/
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: How to drop 2 columns from DB2 table?

Postby shankar_dh » Thu Oct 30, 2014 7:22 pm

Hi Nic,

Thanks for the reply.
But, I have 10.1 version.

Thanks,
Shankar.
shankar_dh
 
Posts: 41
Joined: Fri Mar 22, 2013 1:00 pm
Has thanked: 1 time
Been thanked: 0 time

Re: How to drop 2 columns from DB2 table?

Postby shankar_dh » Mon Nov 17, 2014 7:52 pm

Hi Forum,

Any more suggestions for my post??
shankar_dh
 
Posts: 41
Joined: Fri Mar 22, 2013 1:00 pm
Has thanked: 1 time
Been thanked: 0 time

Re: How to drop 2 columns from DB2 table?

Postby NicC » Tue Nov 18, 2014 4:32 am

You need to do as your original post suggested. Create a new table without the 2 columns that are to be dropped. Populate the new table from the old table. Drop the old table. That appears to be the only way to do it.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: How to drop 2 columns from DB2 table?

Postby heshmahesh » Thu Nov 20, 2014 7:10 pm

Hi,
please check this if it works

ALTER TABLE <table.name> DROP COLUMN <column.name>.
heshmahesh
 
Posts: 7
Joined: Mon Nov 10, 2014 5:49 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to drop 2 columns from DB2 table?

Postby enrico-sorichetti » Thu Nov 20, 2014 7:20 pm

please check this if it works


did You look at the constraints listed in the link posted by Nic ?
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: How to drop 2 columns from DB2 table?

Postby heshmahesh » Thu Nov 20, 2014 7:29 pm

Ya.. i,m sorry.,we can do by the way as Nic said..
heshmahesh
 
Posts: 7
Joined: Mon Nov 10, 2014 5:49 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post