Oracle数据库中要更改主从表中的Record_ID 关键字字段的记录怎么办?
比如主表、从表Record字段记录为0020000001,现在两个表都要改为0015000001?
而且记录有上千条呀!我现在知道土办法,就是先将两个表的记录导出文本文件,查找替换,再删除表中所有记录后把修改后的记录导进来。

解决方案 »

  1.   

    UPDATE tbl
      SET  record='0015000001'
       WHERE record='0020000001'
      

  2.   

    Re: welyngj(不做老实人) 
    这是更新主键的记录值,那样update是不行的,因为有关联关系。Re: rolandzhang() 
    比如:设备表tb_shebei和厂家表tb_changjia,tb_shebei的主键shebei_id是tb_changjia中shebei_bianhao的外键,原来Id的编码规则是0020000001开始递增1的,现在要改为0015000001开始递增1,已经有很多设备记录了。我是想寻求高级一点update方法,现在我已经把数据表记录改好了。谢谢关注!
      

  3.   

    在sql/plus里,执行更新,两个表一起,然后在commit;
    应该可以吧。
      

  4.   

    先Disable外键约束,修改完以后在Enable
      

  5.   

    创建表外键时指定on update cascade
      

  6.   

    sorry,oracle9i不支持on update,用google搜索10g的新特性也没有找到相关信息。
      

  7.   

    建外键的时候加上deferrable;
    create table a (col number(5,0),
                    time date);
    create table b (col number(5,0);
    insert into a values(2,sysdate);
    alter table b add constraint b_FK_a foreign key(col) references a(col) on delete cascade deferrable initially immediate;
    insert into b values(2);
    这时如果
    SQL> update a set col=3 where col=2;
    update a set col=3 where col=2
    *
    ERROR at line 1:
    ORA-02292: integrity constraint (SCOTT.B_FK_A) violated - child record found
    你可以这样设置
     set constraint b_fk_a deferred;Constraint set.SQL> update a set col=3 where col=2;1 row updated.SQL> update b set col=3 where col=2;1 row updated.SQL> commit;Commit complete.SQL> select * from a;       COL TIME
    ---------- ---------
             3 10-AUG-04SQL> select * from b;       COL
    ----------
             3这样就可以update了。
    在你commit后,这个constraint会自动恢复成immediate模式,你也可以用
    set constraint b_fk_a immediate手动恢复