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 > Re-name a column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-30-07, 07:24
sharajanand sharajanand is offline
Registered User
 
Join Date: Jul 2007
Posts: 2
Re-name a column

Hi,
Can you pl tell me the syntax to rename a column. I have tried using - ALTER TABLE COMPANY CHANGE "ELITE ID" ELITE_ID VARCHAR (255);-
this but it didn't work.
Also you can tell how to drop a column froma table. i used - ALTER TABLE COMPANY drop "ELITE ID" ;- this .
Thanks
Reply With Quote
  #2 (permalink)  
Old 07-30-07, 08:08
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
try:

ALTER TABLE tablename RENAME COLUMN oldname TO newname
Reply With Quote
  #3 (permalink)  
Old 07-30-07, 08:52
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You care to tell us which version of DB2 you are using and on which platform? Then we can provide you a link to the manuals where the syntax is described and explained.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 07-31-07, 05:59
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

If you are using DB2 7.1 or DB2 8.1 thenb there is no query to rename column
only you have to drop table

but if you are using DB2 9.1 then you can rename column
Reply With Quote
  #5 (permalink)  
Old 07-31-07, 07:25
sharajanand sharajanand is offline
Registered User
 
Join Date: Jul 2007
Posts: 2
Re-name Column

I am using DB 8. Is there any way to drop that column.
Reply With Quote
  #6 (permalink)  
Old 07-31-07, 07:31
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
in v8 you can:
1. export table ... select only columns you need
2. drop table
3. import table
4. create any foreign keys, triggers, etc if exist

You can also use ALTOBJ stored procedure to do this automatically. But it is not so easy to use it...

Hope this helps,
Grofaty
Reply With Quote
  #7 (permalink)  
Old 08-02-07, 02:31
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

You can also use ALTOBJ stored procedure to do this automatically. But it is not so easy to use it...

Hope this helps,
Grofaty[/QUOTE]


can you please tell step by step process to alter column through ALTOBJ stored procedure
Reply With Quote
  #8 (permalink)  
Old 08-02-07, 03:45
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Open the DB2 Control Center and use the procedure from there. The GUI makes it much easier to provide the correct parameters for the procedure invocation.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #9 (permalink)  
Old 08-02-07, 03:46
guyprzytula guyprzytula is offline
Registered User
 
Join Date: Jun 2006
Posts: 471
this is the syntax (see info center for details)
CALL SYSPROC.ALTOBJ( 'APPLY_STOP_ON_ERROR',
'CREATE TABLE T1 (CL1 VARCHAR(5), CL2 BIGINT)', -1, ?)
replace the create table stmnt with the correct stmnt
__________________
Best Regards, Guy Przytula
DB2 UDB LUW certified V6/7/8
Reply With Quote
  #10 (permalink)  
Old 08-06-07, 02:22
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
the command is pretty simple, but if something goes wrong it can be pain in the a... to recover to previous state. I had a problem of DB2 dropping some object (foreign keys if I remember correctly) and I need to restore database to test computer to see what was the original sintax.

Bottom line is ALTOBJ can solve simple problems, but complex problems can lead to more manual work as it would without this procedure.

So I always prefer export/import functionality...
Hope this helps,
Grofaty
Reply With Quote
  #11 (permalink)  
Old 08-06-07, 20:53
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Read Serge's description of ALTOBJ in this link

http://www.thescripts.com/forum/thread514528.html

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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