--由于业务需求变更,需要对oracle数据库user表的shopcoin结构进行修改。修改表结构,必须是在表空的情况下才可以修改表结构。具体操作步骤:
--1、查看user表结构
--2、对t_user表进行备份
create table t_user_bak as select * from t_user;
--3.1、如果t_user不存在外键,删除t_user表内的数据
delete from t_user;
--3.2、如果t_user存在外键,则更新shopcoin
update t_user set shopcoin = null;
--4、修改表结构
alter table t_user modify shopcoin number(10,2);
--5.1、如果t_user表数据已经被全部删除,还原表结构
insert into t_user select * from t_user_bak;
--5.2、如果t_user表数据没有被清空,只是shopcoin被置空,则更新该字段
update t_user t3 set t3.shopcoin = (select shopcoin from t_user_bak where t_user_bak.id = t3.id) where t3.id in (select id from t_user);
--6、删除备份表
drop table t_user_bak;
--1、查看user表结构
--2、对t_user表进行备份
create table t_user_bak as select * from t_user;
--3.1、如果t_user不存在外键,删除t_user表内的数据
delete from t_user;
--3.2、如果t_user存在外键,则更新shopcoin
update t_user set shopcoin = null;
--4、修改表结构
alter table t_user modify shopcoin number(10,2);
--5.1、如果t_user表数据已经被全部删除,还原表结构
insert into t_user select * from t_user_bak;
--5.2、如果t_user表数据没有被清空,只是shopcoin被置空,则更新该字段
update t_user t3 set t3.shopcoin = (select shopcoin from t_user_bak where t_user_bak.id = t3.id) where t3.id in (select id from t_user);
--6、删除备份表
drop table t_user_bak;