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 DB2 V8 Z/OS

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-11-08, 10:40
Bren99 Bren99 is offline
Registered User
 
Join Date: Dec 2008
Posts: 5
Red face Drop Column DB2 V8 Z/OS

Hi
I am new to DB2 and am wondering is it possible to drop a column from a DB2 table...and if so will the table require a reorg etc after the drop.

Thanks
Reply With Quote
  #2 (permalink)  
Old 12-11-08, 11:30
rdutton rdutton is offline
Registered User
 
Join Date: Dec 2008
Posts: 76
That requires an unload, drop the table and recreate it, and load. You may add a column (with some restrictions), but not drop a column.
Reply With Quote
  #3 (permalink)  
Old 12-11-08, 21:20
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
better way...and this is what is usually done.....

create a new table A similar to the existing table B, however without the dropped column.
Load the new table A with data from existing table B.
Drop the existing table B.
Rename the table A as B.

But then you'll also have to consider which column you are dropping and there can be cases where
the column is used as a constraint for other columns
column is used as a foreign key
coulmn is a pk
etc etc

In such cases you'll get some error messages but make sure you are dead sure about what you are doing and the fact that the column is nowhere else going to be used as otherwise inconsistencies will creep in

AS for reorg, you can easily check whether you require one by running runstats.... better if you do it though
__________________
IBM Certified Database Associate, DB2 9 for LUW
Reply With Quote
  #4 (permalink)  
Old 12-12-08, 05:44
Bren99 Bren99 is offline
Registered User
 
Join Date: Dec 2008
Posts: 5
Talking

Hi Everyone

Thanks for this i will follow the instructions given
Reply With Quote
  #5 (permalink)  
Old 12-12-08, 09:42
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
Or better yet, tell the application to ignore the column and just keep working as usual. Unless, its a huge column that eats up too much disk space, just leave it alone.

Dave
Reply With Quote
  #6 (permalink)  
Old 12-15-08, 12:09
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by Bren99
Is it possible to drop a column from a DB2 table...and if so will the table require a reorg etc after the drop.
If the column is a *text* field (char(n) or varchar(n)), you could reduce its size by changing its datatype to VARCHAR(n) [same n as before] and then filling the column with empty text ('').
If you're at version 9, you could then make the column "invisible", i.e., it will no longer show up with "SELECT * FROM tbl".
Alternatively, RENAME the table then create a view with the original table name, pointing to the renamed table, but with just the columns you want to be visible.

In all cases, you will indeed need a REORG and possibly a REBIND of all static SQL that was using the table.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #7 (permalink)  
Old 12-16-08, 03:17
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by Peter.Vanroose
In all cases, you will indeed need a REORG and possibly a REBIND of all static SQL that was using the table.
The view approach doesn't need a REORG, though.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #8 (permalink)  
Old 12-16-08, 03:29
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by stolze
The view approach doesn't need a REORG, though.
It does, if you precede it with the "make column smaller" step, which I was assuming.
(So, my "alternatively" refers just to my second sentence "If ...", not to my first sentence ;-)
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
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