0
CREATE TABLE SORDER (
    C_NO CHAR(4),
    P_NO CHAR(4),
    QUANTITY SMALLINT,
    PRIMARY KEY (C_NO, P_NO),
    CONSTRAINT CNO_FK FOREIGN KEY (C_NO) REFERENCES CUSTOMER ON DELETE RESTRICT,
    CONSTRAINT PNO_FK FOREIGN KEY (P_NO) REFERENCES PRODUCT2 ON DELETE RESTRICT
);

ORA-00905: 缺少关键字

这是另外两张桌子。

CREATE TABLE PRODUCT2 (
    P_NO CHAR(4) PRIMARY KEY,
    P_NAME CHAR(6),
    PRICES DECIMAL(3,2),
    STOCK SMALLINT
);

CREATE TABLE CUSTOMER2 (
    C_NO CHAR(4) PRIMARY KEY,
    C_NAME CHAR(6),
    CITY CHAR(11)
);
4

2 回答 2

5

Oracle 只支持ON DELETE SET NULLorON DELETE CASCADE作为关键字。的功能ON DELETE RESTRICT是通过省略ON DELETE

CREATE TABLE SORDER (
    C_NO CHAR(4),
    P_NO CHAR(4),
    QUANTITY SMALLINT,
    PRIMARY KEY (C_NO, P_NO),
    CONSTRAINT CNO_FK FOREIGN KEY (C_NO) REFERENCES CUSTOMER2,
    CONSTRAINT PNO_FK FOREIGN KEY (P_NO) REFERENCES PRODUCT2
);

有关详细信息,请参阅手册:http ://docs.oracle.com/cd/B28359_01/server.111/b28286/clauses002.htm#CJABCJJF

从手册中引用:

ON DELETE 子句允许您确定在删除引用的主键或唯一键值时 Oracle 数据库如何自动维护引用完整性。如果省略此子句,则 Oracle 不允许删除父表中的引用键值,这些键值在子表中具有依赖行

这是一个 SQLFiddle:http ://sqlfiddle.com/#!4/07e93/1

于 2013-02-18T11:02:13.483 回答
-6

试试下面的代码

CREATE TABLE SORDER (
    C_NO CHAR(4),
    P_NO CHAR(4),
    QUANTITY SMALLINT,
    PRIMARY KEY (C_NO, P_NO),
    CONSTRAINT CNO_FK FOREIGN KEY (C_NO) REFERENCES CUSTOMER ON DELETE RESTRICT,
    CONSTRAINT PNO_FK FOREIGN KEY (P_NO) REFERENCES PRODUCT2 ON DELETE RESTRICT
);
于 2013-02-18T11:00:21.827 回答