views:

368

answers:

2

Hi,

I am trying to alter a datatype for a derby db column. The current price column is set as DECIMAL(5,0). I would like to alter it to DECIMAL(7,2). I did this :

alter table item alter column price set data type DECIMAL(7,2);

But it did not work, and showing the error:

Error: Only columns of type VARCHAR may have their length altered. 

May I know how is it possible to alter it? Thank you.

A: 

Posgtes Solution :

ALTER TABLE prices_table ALTER price_column TYPE decimal (7,2 )

pavun_cool
I think Derby does not support TYPE, it displays error, Syntax error: Encountered "TYPE" at line 1, column 30.
jl
A: 

Here's a slightly more complicated way to alter the column's data type in this fashion:

  1. Add a new column, of the desired data type
  2. Issue "update ... set new-column = old-column to copy the data from the old column to the new column
  3. drop the old column
  4. Rename the new column to have the name of the old column.

Slightly more steps, but in the end the effect will be the same.

If you have trouble working out the exact details of the SQL to do this, let us know and we'll help.

Bryan Pendleton