oracle中filed_pk值重复,更改Oracle中的主键值

原则是禁用约束,根据键运行你的udates,并重新启用约束。这是一个运行禁用脚本的脚本:

(假设所有约束都在启动时启用)

生成脚本

SELECT 'alter table ' || uc.table_name|| ' disable constraint '|| uc.constraint_name|| ' ;'

FROM user_constraints uc inner join user_cons_columns ucc on uc.constraint_name = ucc.constraint_name where column_name = 'MYCOLUMN_USED_AS_FOREIGN_KEY' and constraint_type='R'

复制/粘贴生成的脚本并运行它

alter table MYTABLE1 disable constraint FK_MYTABLE1 ;

alter table MYTABLE2 disable constraint MYTABLE2 ;

alter table MYTABLE3 disable constraint FK3_MYTABLE3 ;

...

然后更新您的PK值:

update MYTABLE1 set MYFIELD= 'foo' where MYFIELD='bar';

update MYTABLE2 set MYFIELD= 'foo' where MYFIELD='bar';

update MYTABLE3 set MYFIELD= 'foo' where MYFIELD='bar';

commit;

生成启用约束脚本:

SELECT 'alter table ' || uc.table_name|| ' enable constraint '|| uc.constraint_name|| ' ;'

FROM user_constraints uc inner join user_cons_columns ucc on uc.constraint_name = ucc.constraint_name where column_name = 'MYCOLUMN_USED_AS_FOREIGN_KEY' and constraint_type='R'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值