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 > increasing column length

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-08-08, 07:29
itsonlyme44 itsonlyme44 is offline
Registered User
 
Join Date: Dec 2007
Posts: 261
increasing column length

Can I increase the length of a column without affecting the data??
Reply With Quote
  #2 (permalink)  
Old 09-08-08, 08:01
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Only if it is a varchar.

Andy
Reply With Quote
  #3 (permalink)  
Old 09-08-08, 08:18
oracle10gsingh oracle10gsingh is offline
Registered User
 
Join Date: Nov 2007
Posts: 72
not sure with which version of db2 ....V8 or V9 you can use altobj stored procedure ...give it a try ...
Reply With Quote
  #4 (permalink)  
Old 09-08-08, 08:26
itsonlyme44 itsonlyme44 is offline
Registered User
 
Join Date: Dec 2007
Posts: 261
ALTER TABLE KCDWHDUT.T9PST
ALTER COLUMN PRCES_PGM_NM
SET DATA TYPE CHAR(50)

I tried this and it seemed to work and NOT affect the data
Reply With Quote
  #5 (permalink)  
Old 09-08-08, 08:27
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Careful with ALTOBJ: it may not be needed in this case.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #6 (permalink)  
Old 09-08-08, 08:28
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by itsonlyme44
ALTER TABLE KCDWHDUT.T9PST
ALTER COLUMN PRCES_PGM_NM
SET DATA TYPE CHAR(50)

I tried this and it seemed to work and NOT affect the data
What do you mean with "not affect the data"? Did you verify that the results being returned when you query the table will have more spaces padded to the end? If that's the case, everything is fine.

Additionally, you may want to run a REORG on the table.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 09-08-08, 13:17
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by itsonlyme44
Can I increase the length of a column without affecting the data??
Code:
ALTER TABLE ALTER COLUMN colname SET DATATYPE VARCHAR(1000)
(At least, when you are on DB2 v8 for z/OS or later; not sure whether this is possible on other platforms.)

Suppose the original datatype is CHAR(100); the data will be preserved, that is,
all varchar fields will have a length of 100 (i.e., possibly with blanks at the end), but after the ALTER, updated or inserted fields may be of lengths between 0 and 1000. (Or chose anything else than 1000.)
Similarly, a CHAR(100) or a VARCHAR(100) may be altered into a CHAR(1000); the new length must be at least the old length.
__________________
--_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