Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to rename a column on a DB2/400 database table ?

4,127 views
Skip to first unread message

ar

unread,
Feb 17, 2009, 4:53:00 AM2/17/09
to

Hi,

I'd like to rename a table column.
Other DBMS (Informix, PostgreSQL, ...) have something like :
ALTER TABLE my_table RENAME COLUMN old_name TO new_name;

I can't find the DB2 equivalent.

Is there another solution than :
ALTER TABLE my_table ADD COLUMN new_name ...;
UPDATE my_table SET new_name = old_name;
ALTER TABLE my_table DROP COLUMN old_name;

Regards

JTF

unread,
Feb 17, 2009, 8:18:04 AM2/17/09
to

I don't think there is, so your work around, until proven otherwise,
would be the only way.

CRPence

unread,
Feb 17, 2009, 12:10:53 PM2/17/09
to

For tables that are not huge [for which a somewhat more storage
efficient copy by the ALTER feature is required or desirable], a better
method might be to perform the following requests instead; performing
only one data copy, instead of two:

rename table my_table to old_table
create table my_table (x, new_name, z)
-- optionally omit unique & primary keys
insert into my_table (x, new_name, z)
select x, old_name, z from old_table
drop table old_table
/* alter table my_table add constraint
-- if omitted earlier */

Regards, Chuck

Message has been deleted
Message has been deleted

ar

unread,
Feb 18, 2009, 11:43:48 AM2/18/09
to

Thanks for your answers.

Rename table + Create table + Insert into + Drop table can effectively be
a solution except that eventual foreign key constraints from other tables
on my_table's id column aren't preserved.

Regards

0 new messages