我收到此错误ORA-00907:错过右括号

时间:2015-07-17 08:36:23

标签: sql oracle foreign-keys syntax-error ddl

create table passenger(pnr number(10) primary key,
trainnumber number(5) foreign key references train(trainnumber),
noofseats number(4),
price number(4),
doj varchar2(10))

ORA-00907:缺少右括号

2 个答案:

答案 0 :(得分:1)

foreign key表达式是多余的(读:错误)。语法只是添加references

create table passenger(pnr number(10) primary key,
trainnumber number(5) references train(trainnumber), -- here
noofseats number(4),
price number(4),
doj varchar2(10))

答案 1 :(得分:1)

将yout CREATE TABLE语句更改为如下所示

create table passenger(pnr number(10) primary key,
trainnumber number(5), 
noofseats number(4),
price number(4),
doj varchar2(10),
foreign key (trainnumber) references train(trainnumber))