2013-03-19 256 views
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: missing NULL keyword"

通常這是一個簡單的缺少NULL的問題。但是這一次,不管我怎麼看SQL,它看起來都不是那個錯誤。任何人都可以幫助看看他們是否能從另一個角度找到問題所在?謝謝

回答

3

我認爲,你必須

ON DELETE SET CASCADE 

這應該是

ON DELETE CASCADE 

C.F. this

+0

+1我正準備回答同樣的問題:) – Andomar 2013-03-19 18:48:32

+0

非常感謝! :d – Ponnnnn 2013-03-30 05:21:15