ORA-00905:缺少关键字,我缺少哪个关键字?

时间:2020-04-26 04:03:12

标签: sql oracle

我遇到错误

ORA-00905:缺少关键字

我根本不知道出什么问题了,所有的关键字似乎都在那里。我想念什么?谢谢

CREATE TABLE rep_contracts
(
    store_id NUMBER(8),
    name NUMBER(5),
    quarter CHAR(3),
    rep_id NUMBER(5),

    CONSTRAINT rep_contracts_rep_id_store_id_quarter_pk 
        PRIMARY KEY (rep_id, store_id, quarter),

    CONSTRAINT rep_contracts_rep_id_fk 
        FOREIGN KEY (rep_id),
        REFERENCES book_stores (rep_id),

    CONSTRAINT rep_contracts_store_id_fk 
        FOREIGN KEY (store_id),
        REFERENCES book_stores (store_id)
);

1 个答案:

答案 0 :(得分:2)

FOREIGN KEY约束中间有逗号,因此oracle抱怨缺少REFERENCES关键字。删除逗号,代码可以正常工作:

CREATE TABLE rep_contracts
(store_id NUMBER(8),
name NUMBER(5),
quarter CHAR(3),
rep_id NUMBER(5),

CONSTRAINT rep_contracts_rep_id_store_id_quarter_pk PRIMARY KEY (rep_id,store_id,quarter),

CONSTRAINT rep_contracts_rep_id_fk FOREIGN KEY (rep_id)
REFERENCES book_stores (rep_id),
CONSTRAINT rep_contracts_store_id_fk FOREIGN KEY (store_id)
REFERENCES book_stores (store_id));

Demo on dbfiddle