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 08-10-04, 11:15
ApoPen ApoPen is offline
Registered User
 
Join Date: Jul 2004
Location: Ottawa, Canada
Posts: 58
RENAME column

I was wondering what the syntax is to rename an existing column in a table. I tried:

alter table userrole rename column user to username

I found that on some site, but it doesn't work.
Reply With Quote
  #2 (permalink)  
Old 08-10-04, 11:22
dsusendran dsusendran is offline
Registered User
 
Join Date: Apr 2004
Location: Inside Intel
Posts: 165
Talking

You have to drop the table and recreate it. No other way.

Newbie
Reply With Quote
  #3 (permalink)  
Old 08-10-04, 11:22
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I do not know where you found it, but it is not DB2 UDB for LUW syntax.

There is no way to rename a column. You will either have to live with the old column name or:

1) save the data in the table (export)
2) drop table
3) recreate table with column new column name
4) insert the data (import)
5) recreate any objects that were dependant on the table (FK, indexes, etc)

Andy
Reply With Quote
  #4 (permalink)  
Old 08-10-04, 11:25
ApoPen ApoPen is offline
Registered User
 
Join Date: Jul 2004
Location: Ottawa, Canada
Posts: 58
cool, thanks
Reply With Quote
  #5 (permalink)  
Old 08-12-04, 05:20
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

Renaming a column will be a new option in db2 8.2 LUW. But at this time you should do the ARWinner way.

Grofaty
Reply With Quote
  #6 (permalink)  
Old 08-13-04, 09:26
hurmavi hurmavi is offline
Registered User
 
Join Date: Jan 2004
Location: Europe, Finland, Helsinki
Posts: 60
"Rename" can sometimes be done like that:

1) Rename table (TABLE -> TABLEX)
2) Create a view (having name TABLE, selecting all columns AND renaming the problematic one.)
3) Rebind programs

However, note this
1) my knowledge is for z/OS environment
2) and RENAME has serious limitations

Cheers, Bill
Reply With Quote
  #7 (permalink)  
Old 08-13-04, 11:05
fadace fadace is offline
Registered User
 
Join Date: Nov 2002
Location: Switzerland
Posts: 523
Code:
ALTER TABLE YourTable ADD newCol ... ;
UPDATE YourTbl set NewCol=OldCol ;
ALTER TABLE YourTable DROP COLUMN OldCol ;
ALTER TABLE YourTable ADD OldCol ... ;
UPDATE YourTbl set OldCol=NewCol ;
ALTER TABLE YourTable DROP COLUMN NewCol ;
__________________
F. Celaia
DBA Sybase/DB2/Oracle/MS-SQL
Reply With Quote
  #8 (permalink)  
Old 08-13-04, 11:13
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
There currently is no ALTER TABLE ... DROP COLUMN in DB2.

Andy
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