我正在尝试编写此代码
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));
但它告诉我,我有这个错误来创建我的foregin键
第10行的错误:
ORA-02270:此列列表没有匹配的唯一键或主键
答案 0 :(得分: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));