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 > Rename column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-24-08, 15:50
HanbingL HanbingL is offline
Registered User
 
Join Date: Dec 2007
Posts: 15
Rename column

Hi I'm new to DB2, currently our development server is version 8.2
My question is how do I rename a column from x to y.

I've read you can do
ALTER TABLE a RENAME COLUMN x TO y;

but it did not work. Is it even possible?
Reply With Quote
  #2 (permalink)  
Old 01-24-08, 16:36
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
No, there is not a command to rename a column.

You can however use the ALTOBJ Stored procedure to effectively change the column name.

http://publib.boulder.ibm.com/infoce...n/r0011934.htm

You can use the Control Center to "rename" the column and it generates the ALTOBJ statement to perform the work.

Andy
Reply With Quote
  #3 (permalink)  
Old 01-26-08, 05:33
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Two other solutions: (depends on what you need this rename for):

* rename the table, and create a view (with the old table name and with correct column names) referring the original table
* add a column to the table, having the correct name. Then add insert & update triggers to make sure both columns always have identical content. (Or maybe just update existing rows to fill in the correct value for the new column.)
__________________
--_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
  #4 (permalink)  
Old 01-26-08, 07:16
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Yet another alternative:
  1. add a new column with the correct name
  2. copy all values from old column to new column
  3. recreate all objects referring to the old table and point them to the new column (i.e. triggers, functions, views, etc.)
  4. drop old column

p.s: I think the easiest way is the first approach listed by Peter.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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