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 > Expanding a Column in a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-22-09, 14:09
opowell opowell is offline
Registered User
 
Join Date: Jun 2009
Posts: 14
Question Expanding a Column in a table

Version 8.2 on Linux.
Background: I have not used db2 since 7.1 and earlier.
Question: Can DB2 now allow you to expand a column in place, if not which is a smoother transition, adding a new column and moving the data to the new column and then renaming the column and dropping the old column. Or creating a new tablewith the expanded column and importing the data, then re-naming the table.
Reply With Quote
  #2 (permalink)  
Old 06-22-09, 14:27
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Depends what data type and if you have any RI or other ref linked to it.

If you decide to go with new object. then:
1. create new table.
2. load from cursor from old to new.
3. rename old.
4. rename new.
5. test
6. drop old
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #3 (permalink)  
Old 06-22-09, 14:47
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
If by expand, you mean make larger, like increasing the size of a varchar, then you can do that kind of thing in place with just the ALTER TABLE command.

Andy
Reply With Quote
  #4 (permalink)  
Old 06-22-09, 15:08
opowell opowell is offline
Registered User
 
Join Date: Jun 2009
Posts: 14
Question More information

More information. After digging around and drawing back db2 commands with cob webs attached. The table is actually only has two columns with no primary key or indexes. both columns are char(25) and both nullable. The column that I need to expand is the last column in the table.

old: column name CHAR(25)
new column name CHAR(50).

This can be complete by altering the column in place.
Reply With Quote
  #5 (permalink)  
Old 06-22-09, 16:17
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Yes. have you looked at the SQL Ref 2 manual as Andy suggested?

alter table tabschema.tabname alter column col2 set DATA TYPE char(4)"
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #6 (permalink)  
Old 06-23-09, 11:16
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
You can alter only VARCHAR columns; the record size does not change right away; but you CANNOT alter CHAR columns because then each record has to change causing all kinds of havoc.
__________________
mota
Reply With Quote
  #7 (permalink)  
Old 06-23-09, 12:27
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Quote:
Originally Posted by dbamota
You can alter only VARCHAR columns; the record size does not change right away; but you CANNOT alter CHAR columns because then each record has to change causing all kinds of havoc.
Strange, because I did just that yesterday.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #8 (permalink)  
Old 06-23-09, 12:35
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Cougar,
The OP is on V 8.2 and the only thing you could alter was varchar. It has changed in V9 and beyond.

Andy
Reply With Quote
  #9 (permalink)  
Old 06-23-09, 15:05
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
How many records were there in the table? Was there an index?how long did it take to make the change?
__________________
mota
Reply With Quote
  #10 (permalink)  
Old 06-23-09, 15:10
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Quote:
Originally Posted by ARWinner
Cougar,
The OP is on V 8.2 and the only thing you could alter was varchar. It has changed in V9 and beyond.

Andy
I guess I missed db2 level. Thank you.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #11 (permalink)  
Old 06-23-09, 15:11
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Quote:
Originally Posted by dbamota
How many records were there in the table? Was there an index?how long did it take to make the change?
Does it really matter in this case? Yes, there considerations that have to be taken into account.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
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