Here is my code:
SQL> CREATE TABLE manufacturer( manufacturer_id integer primary key, manufacturer_name varchar2(20) ); Table created. SQL> CREATE TABLE models( model_id integer primary key, model_name varchar2(20), model_year integer, eng_cylinder integer, eng_horsepower integer, manufacturer_id int foreign key references manufacturer(manufacturer_id) );
and it gave me this error:
ERROR at line 1: ORA-00907: missing right parenthesis
What is wrong with parenthesis in my code? this only happens when i set foreign key.
Note: i am using SQL cmd from Oracle Database 11g Express Edition.
I’ve tried making theses tables on MySQL and it worked fine.
Advertisement
Answer
No “FOREIGN KEY” keyword is used for inline constraints. So, like this:
CREATE TABLE manufacturer (manufacturer_id integer primary key, manufacturer_name varchar2(20)); CREATE TABLE models (model_id integer primary key, model_name varchar2(20), model_year integer, eng_cylinder integer, eng_horsepower integer, manufacturer_id int constraint models_fk1 references manufacturer(manufacturer_id));