Home > database >  ORA-00907: missing right parenthesis when using FK
ORA-00907: missing right parenthesis when using FK

Time:03-09

SQL>
SQL> CREATE TABLE Recipe
(Quantity_used DECIMAL (2,1)
FOREIGN KEY "ICECREAM_ID"
REFERENCES icecreamGT(Icecream_id),
FOREIGN KEY (ingredient_id) REFERENCES ingredient (Ingredient_name),
);
  2    3    4    5    6  FOREIGN KEY "ICECREAM_ID"
*
ERROR at line 3:
ORA-00907: missing right parenthesis

picture of code and structure

UPDATED: new code with adjusted commas and parenthesis

CREATE TABLE Recipe 
(
Quantity_used DECIMAL (2,1),
FOREIGN KEY (ID_icecream)
REFERENCES icecreamGT(Icecream_id)
FOREIGN KEY (ID_ingredient)
REFERENCES ingredient(Ingredient_name)
);

new code

CodePudding user response:

Your statement does not have:

  • An icecream_id column in the recipe table;
  • An ingredient_id column in the recipe table;
  • Commas in the correct places;
  • () Brackets around the "ICECREAM_ID" identifier in the column list of the foreign key.

I.e.:

CREATE TABLE Recipe(
  Quantity_used   DECIMAL (2,1),
  icecream_id     NUMBER,
  ingredient_id   NUMBER,
  FOREIGN KEY (ICECREAM_ID) REFERENCES icecreamGT(Icecream_id),
  FOREIGN KEY (ingredient_id) REFERENCES ingredient (Ingredient_name)
);

db<>fiddle here

  • Related