You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Amir Michail <am...@gmail.com> on 2008/02/19 19:07:59 UTC

moving columns between tables

Hi,

Is there a way to easily move a column from one table to another (as
easy as a rename say)?

If not, maybe such a command could be added?

Amir

Re: moving columns between tables

Posted by "A. Rick Anderson" <ar...@pobox.com>.
Amir Michail wrote:
> Can't all this be done automatically with a new move command?
> Amir

Absolutely.  To quote Debrunner, all you have to do, is

"get involved (code, test and or document etc.) yourself ... 
http://wiki.apache.org/db-derby/DerbyDev"

-- 
A. Rick Anderson


Re: moving columns between tables

Posted by Narayanan <V....@Sun.COM>.
Amir Michail wrote:
> On Feb 19, 2008 1:25 PM, Bryan Pendleton <bp...@amberpoint.com> wrote:
>   
>>> Is there a way to easily move a column from one table to another (as
>>> easy as a rename say)?
>>>       
>> alter table newtable add column newcolumn whatever-data-type;
>> update newtable set newcolumn = (value that the newcolumn should have);
>> alter table oldtable drop column oldcolumn;
>>
>> You'll also have to do some work to drop any constraints on
>> the old column from the old table, then add those constraints
>> to the new column in the new table once it's populated.
>>     
>
> Can't all this be done automatically with a new move command?
>
> Amir
>   
If by "automatically" you mean one command to do everything,
you could consider whether writing a stored procedure that does
all that you want and calling it would be good enough.

You can read more about stored procedures in derby here
http://wiki.apache.org/db-derby/DerbySQLroutines
>   
>> thanks,
>>
>> bryan
>>
>>
>>
>>     


Re: moving columns between tables

Posted by Amir Michail <am...@gmail.com>.
On Feb 19, 2008 1:25 PM, Bryan Pendleton <bp...@amberpoint.com> wrote:
> > Is there a way to easily move a column from one table to another (as
> > easy as a rename say)?
>
> alter table newtable add column newcolumn whatever-data-type;
> update newtable set newcolumn = (value that the newcolumn should have);
> alter table oldtable drop column oldcolumn;
>
> You'll also have to do some work to drop any constraints on
> the old column from the old table, then add those constraints
> to the new column in the new table once it's populated.

Can't all this be done automatically with a new move command?

Amir

>
> thanks,
>
> bryan
>
>
>

Re: moving columns between tables

Posted by Bryan Pendleton <bp...@amberpoint.com>.
> Is there a way to easily move a column from one table to another (as
> easy as a rename say)?

alter table newtable add column newcolumn whatever-data-type;
update newtable set newcolumn = (value that the newcolumn should have);
alter table oldtable drop column oldcolumn;

You'll also have to do some work to drop any constraints on
the old column from the old table, then add those constraints
to the new column in the new table once it's populated.

thanks,

bryan