2013-11-28 55 views
0

我試圖創建的Oracle 11g Express中的表,但是我收到一個錯誤「ORA-00904:無效的標識符」創建表錯誤 - 無效的標識符

CREATE TABLE Ingredients(
IngredientID INTEGER  PRIMARY KEY  NOT NULL, 
IngredientName VARCHAR(255), 
IngredientClassID SMALLINT NOT NULL, 
MeasureAmountID  SMALLINT NOT NULL, 
CHECK (IngredientID>0), 
CHECK (IngredientClassID>0), 
FOREIGN KEY (IngredientClassID) REFERENCES Ingredient_Classes, 
     ON UPDATE NO ACTION, 
     ON DELETE CASCADE, 
FOREIGN KEY (MeasureAmountID) REFERENCES Measurements, 
     ON UPDATE NO ACTION, 
     ON DELETE CASCADE 
); 

回答

1

你錯過表名(columnName)方法中外鍵,還添加了額外的逗號。 檢查正確的語法http://docs.oracle.com/cd/E17952_01/refman-5.5-en/create-table-foreign-keys.html

我還沒有測試過下面的腳本。

CREATE TABLE Ingredients(
IngredientID INTEGER  PRIMARY KEY  NOT NULL, 
IngredientName VARCHAR(255), 
IngredientClassID SMALLINT NOT NULL, 
MeasureAmountID  SMALLINT NOT NULL, 
CHECK (IngredientID>0), 
CHECK (IngredientClassID>0), 
FOREIGN KEY (IngredientClassID) REFERENCES Ingredient_Classes(ColumnName) 
     ON UPDATE NO ACTION 
     ON DELETE CASCADE, 
FOREIGN KEY (MeasureAmountID) REFERENCES Measurements(ColumnName) 
     ON UPDATE NO ACTION 
     ON DELETE CASCADE 
); 
+0

DERP的時刻,是的,我沒有忘記列名。然而,這一個產生了一個新的錯誤「ORA-00905:缺少關鍵字」 – user2923395