【问题标题】:I am getting following error when I try to add constraint尝试添加约束时出现以下错误
【发布时间】:2017-11-01 20:56:51
【问题描述】:

我需要弄清楚 sfpl_plan_desc 中哪些记录的值未能通过特定的 FK。

ALTER TABLE SFPL_PLAN_DESC  ADD CONSTRAINT SFPL_PLAN_DESC_FK4 FOREIGN KEY ( DOC_TYPE ,  PLAN_TYPE , WORK_FLOW )  REFERENCES SFFND_DOC_TYPE_DEF


ERROR at line 1:
ORA-02298: cannot validate (SFMFG.SFPL_PLAN_DESC_FK4) - parent keys not found

【问题讨论】:

    标签: oracle foreign-keys ddl


    【解决方案1】:

    简单,

    Select distinct 
           DOC_TYPE
         , PLAN_TYPE
         , WORK_FLOW
      from SFPL_PLAN_DESC c
     where not exists (select 1 from SFFND_DOC_TYPE_DEF p
                        where p.doc_type = c.doc_type
                          and p.plan_type = c.plan_type
                          and p.work_flow = c.work_flow)
    

    应该显示丢失的外键。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-26
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      相关资源
      最近更新 更多