Reputation: 2461
Can anyone tell me what's wrong with this code? I couldn't figure out what's wrong with it. The only error message I got is "missing right parenthesis". Please help
CREATE TABLE employee (
emp_no NUMBER(3) NOT NULL PRIMARY KEY,
emp_name VARCHAR(15) NOT NULL UNIQUE,
emp_salary DECIMAL(8,2) NOT NULL,
djob VARCHAR(15) NOT NULL FOREIGN KEY REFERENCES depot(djob)
);
Upvotes: 0
Views: 51
Reputation: 366
Here is an example: http://sqlfiddle.com/#!4/19250
CREATE TABLE dept (
deptno number PRIMARY KEY,
dname varchar2(100));
CREATE TABLE employee (
emp_no NUMBER(3) NOT NULL PRIMARY KEY,
emp_name VARCHAR(15) NOT NULL UNIQUE,
emp_salary DECIMAL(8,2) NOT NULL,
djob number NOT NULL,
CONSTRAINT fk_job FOREIGN KEY (djob) REFERENCES dept(deptno)
);
Upvotes: 0
Reputation: 185
should't the last line be with foreign key as separate line?
`
CREATE TABLE employee (
emp_no NUMBER(3) NOT NULL PRIMARY KEY,
emp_name VARCHAR(15) NOT NULL UNIQUE,
emp_salary DECIMAL(8,2) NOT NULL,
djob VARCHAR(15) NOT NULL,
FOREIGN KEY
REFERENCES depot(djob)
);
Upvotes: 0
Reputation: 1269953
The issue is the FOREIGN KEY
. You can simply do:
CREATE TABLE employee (
emp_no NUMBER(3) NOT NULL PRIMARY KEY,
emp_name VARCHAR2(15) NOT NULL UNIQUE,
emp_salary DECIMAL(8,2) NOT NULL,
djob VARCHAR(15) NOT NULL REFERENCES depot(djob)
);
For the in-line declaration, FOREIGN KEY
is not necessary.
Note that I also changed VARCHAR()
to VARCHAR2()
, which is more accepted for Oracle.
Upvotes: 2