oracle資料庫(ORA-02270:此列表的唯一或主鍵不匹配)

self_control發表於2014-12-16
在給表加外來鍵引用時,報出 ORA-02270:此列表的唯一或主鍵不匹配。

點選(此處)摺疊或開啟

  1. /*==============================================================*/
  2. /* Table: QX_GWYH */
  3. /*==============================================================*/
  4. create table QX_GWYH
  5. (
  6.    ID VARCHAR2(32),
  7.    RY_DM VARCHAR2(11),
  8.    GW_DM VARCHAR2(32)
  9. );

  10. comment on table QX_GWYH is
  11. \'崗位使用者表\';

  12. comment on column QX_GWYH.ID is
  13. \'主鍵\';

  14. comment on column QX_GWYH.RY_DM is
  15. \'人員程式碼\';

  16. comment on column QX_GWYH.GW_DM is
  17. \'崗位程式碼\';

  18. /*==============================================================*/
  19. /* Table: QX_RY */
  20. /*==============================================================*/
  21. create table QX_RY
  22. (
  23.    RY_DM VARCHAR2(11) not null,
  24.    RY_MC VARCHAR2(100),
  25.    constraint PK_QX_RY primary key (RY_DM)
  26. );

  27. comment on table QX_RY is
  28. \'人員表\';

  29. comment on column QX_RY.RY_DM is
  30. \'人員程式碼\';

  31. comment on column QX_RY.RY_MC is
  32. \'人員名稱\';

  33. /*==============================================================*/
  34. /* Table: QX_XTYH */
  35. /*==============================================================*/
  36. create table QX_XTYH
  37. (
  38.    DLZH VARCHAR2(50) not null,
  39.    RY_DM VARCHAR2(11),
  40.    PASSWORD VARCHAR2(50),
  41.    constraint PK_QX_XTYH primary key (DLZH)
  42. );

  43. comment on table QX_XTYH is
  44. \'使用者表\';

  45. comment on column QX_XTYH.DLZH is
  46. \'登入賬號\';

  47. comment on column QX_XTYH.RY_DM is
  48. \'人員程式碼\';

  49. comment on column QX_XTYH.PASSWORD is
  50. \'登入密碼\';



  51.    
  52. alter table QX_GWYH
  53.    add constraint FK_QX_GWYH_REFERENCE_QX_XTYH foreign key (RY_DM)
  54.       references QX_XTYH (RY_DM);

  55. alter table QX_XTYH
  56.    add constraint FK_QX_XTYH_REFERENCE_QX_RY foreign key (RY_DM)
  57.       references QX_RY (RY_DM);
問題在於 引用表的欄位沒用唯一約束。

點選(此處)摺疊或開啟

  1. alter table QX_XTYH
  2.    add constraint UK_QX_XTYH_RYDM unique (RY_DM)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30066956/viewspace-1369791/,如需轉載,請註明出處,否則將追究法律責任。

相關文章