0

我正在尝试编写此代码

CREATE TABLE BOOK
(BOOKNO NUMBER(4) PRIMARY KEY NOT NULL,
BTIME NUMBER(24,22),
CNAME VARCHAR2(10) ,
BTYPE VARCHAR2(13),
TABLENO NUMBER(2),
EMPNO NUMBER(4),
ENAME VARCHAR2(10),
BDATE  DATE DEFAULT '23-MAR-13',
FOREIGN KEY (CNAME) REFERENCES BOOK (CNAME));

但它告诉我,我在创建外键时遇到了这个错误

第 10 行出现错误:
ORA-02270:此列列表没有匹配的唯一键或主键

4

1 回答 1

0

Oracle/PLSQL:ORA-02270 错误

您尝试使用唯一键或主键引用表,但您列出的列与主键不匹配,或者此表不存在主键。

CREATE TABLE BOOK
(BOOKNO NUMBER(4) PRIMARY KEY NOT NULL,
BTIME NUMBER(24,22),
CNAME VARCHAR2(10) ,
BTYPE VARCHAR2(13),
TABLENO NUMBER(2),
EMPNO NUMBER(4),
ENAME VARCHAR2(10),
BDATE  DATE DEFAULT '23-MAR-13',
FOREIGN KEY (CNAME) REFERENCES BOOK (BOOKNO));

更新

CREATE TABLE BOOK
    (BOOKNO NUMBER(4) PRIMARY KEY NOT NULL,
    BTIME NUMBER(24,22),
    CNAME VARCHAR2(10) NOT NULL UNIQUE,
    BTYPE VARCHAR2(13),
    TABLENO NUMBER(2),
    EMPNO NUMBER(4),
    ENAME VARCHAR2(10),
    BDATE  DATE DEFAULT '23-MAR-13',
    FOREIGN KEY (CNAME) REFERENCES BOOK (CNAME));
于 2013-04-09T12:43:24.283 回答