日期:2014-05-17  浏览次数:20860 次

如何更改数据表中的列名?
如何更改数据表中的列名?
比如:我的表cardinfo中有一字段为number
我现在想将number改为cardid   (表中已有数据)
请问如何更改字段名?

------解决方案--------------------

创建一个与这个表结果相同的表然后把数据导入到这个表里,删除cardinfo创建一个新的cardinfo,再把数据导回来
------解决方案--------------------
Add Column Example
The following statement adds a column named thriftplan of datatype NUMBER with a maximum of seven digits and two decimal places and a column named loancode of datatype CHAR with a size of one and a NOT NULL integrity constraint:

ALTER TABLE emp
ADD (thriftplan NUMBER(7,2),
loancode CHAR(1) NOT NULL);

Modify Column Examples
The following statement increases the size of the thriftplan column to nine digits:

ALTER TABLE emp
MODIFY (thriftplan NUMBER(9,2));


Because the MODIFY clause contains only one column definition, the parentheses around the definition are optional.

The following statement changes the values of the PCTFREE and PCTUSED parameters for the emp table to 30 and 60, respectively:

ALTER TABLE emp
PCTFREE 30
PCTUSED 60;


------解决方案--------------------
9i以上的版本可以使用
alter table table_name RENAME COLUMN column_name to NEW_COLUMN_NAME;
------解决方案--------------------
也许只能先Add Column cardid ,然后update这个cardid等于 number。

最后在drop comumn number


------解决方案--------------------
hongqi162(失踪的月亮)
说的太正确了

------解决方案--------------------
hongqi162(失踪的月亮)
我也帮着顶一下!
还有在Oracle客户端中对表的操作会自动生成SQL语句,你可以参照!
------解决方案--------------------
alter table cardinfo rename column number to cardid;