2014-10-20 71 views
0

不知道我錯過了什麼來得到這個錯誤?SQL錯誤:ORA-00905:缺少關鍵字ON刪除沒有行動外鍵

Error starting at line : 95 in command - 
    ALTER TABLE Official_Language ADD CONSTRAINT Language_Official_Language_fk 
    FOREIGN KEY (language_code) 
    REFERENCES Language (language_code) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION 
    NOT DEFERRABLE 
    Error report - 
    SQL Error: ORA-00905: missing keyword 
    00905. 00000 - "missing keyword" 
    *Cause:  
    *Action: 

任何幫助表示讚賞:-)感謝

+3

移除MySQL的關鍵字。你有一個Oracle錯誤。 – 2014-10-20 11:54:04

回答

1
ALTER TABLE Official_Language ADD CONSTRAINT Language_Official_Language_fk 
FOREIGN KEY (language_code) 
REFERENCES Language (language_code) 
NOT DEFERRABLE; 

可能的選擇是在刪除[CASCADE | SET NULL] 默認情況下(如果省略ON DELETE),它與您寫的相同。

不可推遲是默認的(你也可以省略)

0

這一個應該工作:

ALTER TABLE Official_Language ADD CONSTRAINT Language_Official_Language_fk 
    FOREIGN KEY (language_code) 
    REFERENCES Language (language_code) 
    NOT DEFERRABLE; 

默認爲「不採取行動」,Oracle不會做出刪除/更新任何區別。

可能的關鍵字是ON DELETE CASCADEON DELETE SET NULL

0

與MySQL不同,Oracle不支持ON DELETE NO ACTION - 選項有:

  • (沒有)(即實施參照完整性)
  • ON DELETE CASCADE(即級聯刪除)
  • ON DELETE SET NULL(更新密鑰爲null,如果列允許爲空)

Reference

SqlFiddle here