创建表错误 - 标识符无效

时间:2013-11-28 05:31:41

标签: oracle

我正在尝试在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 个答案:

答案 0 :(得分:1)

您是否错过了外键中的TableName(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
);