同一表中将两字段名互换
求教
要将main表中的remark字段和purpose字段的字段名互换,
这个sql脚本应该怎么写
------解决方案--------------------alter table main rename column remark to tmp;
alter table main rename column purpose to remark;
alter table main rename column tmp to purpose;
------解决方案--------------------create table m(remark,purpose)
as
select purpose,remark
from t;
drop table t;
rename m to t;
------解决方案--------------------修改表 字段名
alter table tablename rename column oldname to newname ;
------解决方案--------------------create table main (remark varchar2(10),purpose varchar2(10));
insert into main values('remark','purpose');
insert into main values('remark','purpose');
commit;
select * from main
REMARK PURPOSE
---------- ----------
remark purpose
remark purpose
alter table main rename column remark to tmp;
alter table main rename column purpose to remark;
alter table main rename column tmp to purpose;
select * from main
PURPOSE REMARK
---------- ----------
remark purpose
remark purpose
------解决方案--------------------为什么要互换?你互换里面有数据吗?没数据的话你按新定义存数据不就得了,有数据的话,你把数据更新互换也就好了。