How to alter a column datatype for derby database?

为君一笑 提交于 2019-11-30 17:17:07

Here is the Derby SQL script to change column MY_TABLE.MY_COLUMN from BLOB(255) to BLOB(2147483647):

ALTER TABLE MY_TABLE ADD COLUMN NEW_COLUMN BLOB(2147483647);
UPDATE MY_TABLE SET NEW_COLUMN=MY_COLUMN;
ALTER TABLE MY_TABLE DROP COLUMN MY_COLUMN;
RENAME COLUMN MY_TABLE.NEW_COLUMN TO MY_COLUMN;
jr1964

I think you can do like this:

ALTER TABLE SCHEMA.TABLE ALTER "COLUMN-NAME" SET DATA TYPE VARCHAR(255);

(column-Name SET DATA TYPE VARCHAR(integer)) for Datatype String as an example...

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.

You can alter table like this:

ALTER TABLE [table] ALTER COLUMN [column] SET DATA TYPE [type];

Or in Rails, just use:

change_column :table_name, :column_name, :integer

Posgtes Solution :

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!