database - Oracle SQL error ORA-00907: missing right parenthesis -


how all?

basically i've written bit of sql code create table keep getting error stated in title, idea why?

here's code:

    create table staff(     staffid int not null primary key,     firstname varchar2(20),     lastname varchar2(20),     addressline_1 varchar2(30),     city varchar2(15),     postcode varchar2(7),     telephone varchar2(15),     salary decimal (19,4),     branchid int foreign key references branches(branchid)     ); 

also here code 'branches' table

    create table branches     (branchid int not null primary key,     addressline_1 varchar2(30),     city varchar2(15),     postcode varchar2(7),     telephone varchar2(15),     manager varchar2(20)); 

any appreciated!

thank you!

a few suggestions:

first make sure branches table has been created.

second, alter create table code following:

create table staff(     staffid int not null primary key,     firstname varchar(20),     lastname varchar(20),     addressline_1 varchar2(30),     city varchar2(15),     postcode varchar2(7),     telephone varchar2(15),     salary decimal (19,4),     branchid int,     constraint fk_branchid foreign key (branchid) references branches(branchid)     ); 

see sql fiddle demo. syntax create foreign key during table creation is:

create table table_name (   column1 datatype null/not null,   column2 datatype null/not null,   ...    constraint fk_column     foreign key (column1, column2, ... column_n)     references parent_table (column1, column2, ... column_n) ); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -