创建关联实体表

时间:2013-03-19 18:41:32

标签: sql oracle

以下表格已成功实施:

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,它看起来都不是错误。任何人都可以帮助看看他们是否可以从另一个角度找到问题所在?谢谢

1 个答案:

答案 0 :(得分:3)

我想你在哪里

ON DELETE SET CASCADE

这应该是

ON DELETE CASCADE

c.f。 this