select *
from sc_tm_warehouse w
where w.sc_tm_warehouse_id in (1020898,1022938)
for update;我要将PK键sc_tm_warehouse_id=1020898,1022938,这两条数据互换,但执行时报违反唯一约束PK
请问要怎么操作呢?谢谢大家了
这2条数据都有其他表关联外键的。
解决方案 »
- 求教:在9204下执行dbms_metadata.get_ddl() 报错
- 请教一个正则表达式
- ORACLE有没有单机版 与服务器版有什么区别 与ACCESS有什么区别
- 高手看看,这个删除的算法怎么做效率最高?
- 急!用什么select语句查询数据库里的所有函数?
- 请大家帮忙,我创建用户时少了那些权限?
- ORCALE客户端连接问题。
- 插入数据也出错?
- oracle 官方(metalink)上的关于EXPORT/IMPORT字符集转换的文章
- ORACLE中如何使用DBlink访问其他数据库。如何调用存储过程?求高人指点
- 求一段根据条件动态检索的SQL文
- 求助,PK键,2条PK键数据要互换,怎么操作呢?
再把那个修改的XXXX改成第二条的值.
这是一个仓库(sc_tm_warehouse ),有门店,库存等很多表相关联。
set a.x=b.x
from a, temp b
where a.id<>b.id and a.id=1020898update a
set a.x=b.x
from a, temp b
where a.id<>b.id and a.id=1022938drop table temp
set a.x=b.x
from a, temp b
where a.id<>b.id and a.id=1020898update a
set a.x=b.x
from a, temp b
where a.id<>b.id and a.id=1022938drop table temp
这样的话,只要改主表就可以了,从表就不用动了.
如果你的表设计是按规范设计的话.
create table t_fk(id number,class varchar2(10),fid number);
alter table t_pk add constraint t_pk1 primary key (id);
alter table t_fk add constraint t_pk2 primary key (id);
alter table t_fk add constraint t_pk_fk foreign key (fid) references t_pk(id);insert into t_pk values(1,'zhangsan',10);
insert into t_pk values(2,'lisi',20);
commit;
insert into t_fk values(100,'class1',1);
insert into t_fk values(200,'class2',2);
commit;--1、禁掉外键:
alter table t_fk disable constraint t_pk_fk;
--2、备份
create table t_pk_bak as select * from t_pk where id in(1,2);
--3、删除数据
delete from t_pk where id in(1,2);
--4、改变PK还原数据
insert into t_pk select decode(id,1,2,1),name,age from t_pk_bak ;
--5、还原外键
alter TABLE t_fk enable constraint t_pk_fk;
--6、drop备份
drop table t_pk_bak;