database - Oracle SQL foreign key not working -


table #1:

create table department(   dept_id char(02) primary key,    dept_name varchar(20) ,    manager_id char(03),    location_id char(04) ) 

table #2:

create table employee (    employee_id char(03) primary key,     first_name varchar(10),     dept_id char(02) foreign key references department(dept_id),    email varchar(10),     tel_no char(10),    hire_date date ) 

when try create foreign key in table #2. following error.

ora-00907: missing right parenthesis 

please kind enough advice me whats wrong in code , how can fix this?

just remove foreign key:

create table employee (    employee_id char(03) primary key,     first_name varchar(10),     dept_id char(02) references department(dept_id),    email varchar(10),     tel_no char(10),    hire_date date ) 

because foreign keys reference primary key default,

create table employee (    employee_id char(03) primary key,     first_name varchar(10),     dept_id char(02) references department,    email varchar(10),     tel_no char(10),    hire_date date ) 

would sufficient.

nb foreign key column not mandatory -- didn't specify not null anywhere, it's optional foreign key.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -