1

下表已成功实施:

CREATE TABLE Patient (
Patient_ID  CHAR(5)     CONSTRAINT Patient_PK PRIMARY KEY,
First_Name  VARCHAR2(20)    NOT NULL,
Last_Name   VARCHAR2(20)    NOT NULL,
DoB     DATE,
 Sex        CHAR(1),
 Phone      NUMBER(10),
 Address    VARCHAR2(40)
);

CREATE TABLE Physician (
Physician_ID    CHAR(5)     CONSTRAINT Physician_PK PRIMARY KEY,
First_Name  VARCHAR2(20)    NOT NULL,
Last_Name   VARCHAR2(20)    NOT NULL,
Department_ID   CHAR(5) ,
  CONSTRAINT physician_FK_dept
   FOREIGN KEY (Department_ID)
   REFERENCES Department (Department_ID)
   ON DELETE SET NULL
);

但是当我尝试在两个表之间创建关联实体时:

CREATE TABLE Visit (
Visit_ID    CHAR(5)     CONSTRAINT Visit_PK PRIMARY KEY,
Visit_date  DATE        NOT NULL,
Patient_ID  VARCHAR2(20)    NOT NULL,
Physician_ID    VARCHAR2(20),
  CONSTRAINT visit_FK_patient
   FOREIGN KEY (Patient_ID)
   REFERENCES Patient (Patient_ID)
   ON DELETE SET CASCADE,
  CONSTRAINT visit_FK_physician
   FOREIGN KEY (Physician_ID)
   REFERENCES Physician (Physician_ID)
   ON DELETE SET NULL
);

由于错误而失败:

ORA-00908: 缺少 NULL 关键字"

通常,缺少 NULL 是一件简单的事情。但是这一次,无论我如何看待 SQL,它看起来都不是错误。任何人都可以帮忙看看他们是否可以从另一个角度找到问题所在?谢谢

4

1 回答 1

3

我想你在哪里

ON DELETE SET CASCADE

这应该是

ON DELETE CASCADE

参考这个

于 2013-03-19T18:47:50.150 回答