如何更改derby数据库的列数据类型? [英] How to alter a column datatype for derby database?

查看:491
本文介绍了如何更改derby数据库的列数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改derby db列的数据类型。当前价格列设置为DECIMAL(5,0)。我想把它改为DECIMAL(7,2)。我这样做:

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.

推荐答案

这里是Derby SQL脚本将列MY_TABLE.MY_COLUMN从BLOB(255)更改为BLOB(2147483647) :

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;

这篇关于如何更改derby数据库的列数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆